|
-
May 3rd, 2011, 11:17 AM
#1
Thread Starter
Fanatic Member
[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
Last edited by nader; May 3rd, 2011 at 11:37 AM.
-
May 3rd, 2011, 06:17 PM
#2
Hyperactive Member
Re: How can I make find properties from workbook to another workbooks?
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???
-
May 3rd, 2011, 07:04 PM
#3
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 6th, 2011, 07:54 AM
#4
Thread Starter
Fanatic Member
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
-
May 6th, 2011, 08:19 AM
#5
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")
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 6th, 2011, 09:57 AM
#6
Thread Starter
Fanatic Member
Re: How can I make find properties from workbook to another workbooks?
Thank you it succeed with me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|