[RESOLVED] How can I make find properties from workbook to another workbooks?
this code is to find Anyword in any worksheets in the workbook
How can I make frind from workbook to another workbooks?...by the way I'm using mS 2007
vb Code:
Dim wsh As Worksheet
For Each wsh In Workbook
wsh.Cells.Find(What:="Anyword").Activate
Next
Re: How can I make find properties from workbook to another workbooks?
Quote:
How can I make frind from workbook to another workbooks?
By referring to that workbook in your code.
What exactly do you need?
Is there a specific workbook you need to get it from where the name/location isn't going to change, do you need to have an open file dialog so you can select the workbook, do you have a list with all the workbooks that you need???
Re: How can I make find properties from workbook to another workbooks?
if the workbooks are already open
vb Code:
for each wb in workbooks
for each wsh in wb.sheets
'do stuff
next
next
if not open you have to determine which workbooks to open to search the sheets
if is pointless activating a cell within a loop unless you exit the loop immediately as the loop will continue and only the last activated cell will be relevant
Re: How can I make find properties from workbook to another workbooks?
I tried this way and it succeeds with me.
D
vb Code:
im wbt As Workbook
Set wbt = Workbooks("tow workbooks")
Dim wk As Workbook
Set wk = Workbooks.Open("C:\wb.xlsx")
For Each wsh In wk.Sheets
Dim r As Range
Set r = wsh.Cells.Find(What:=wbt.Sheets(1).TextBox1.Text)
If Not r Is Nothing Then
wsh.Activate
r.Activate
End If
Next wsh
But if I open the Workbook(wb) and make this line of code
Code:
Set wk = Workbooks("C:\wb.xlsx")
it showed me un error " subscript out of range
Re: How can I make find properties from workbook to another workbooks?
you can only use the name of the workbook, not the fullname
vb Code:
set wk = workbooks("wb.xlsx")
try like this to find if workbook is already open, or open if not
vb Code:
dim wb as workbook
for each wb in workbooks
if wb.name = "wb.xlsx" then exit for
next
if wb is nothing then set wb = workbooks.open("C:\wb.xlsx")
Re: How can I make find properties from workbook to another workbooks?
Thank you it succeed with me.