Results 1 to 6 of 6

Thread: [RESOLVED] How can I make find properties from workbook to another workbooks?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Resolved [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:
    1. Dim wsh As Worksheet
    2. For Each wsh In Workbook
    3. wsh.Cells.Find(What:="Anyword").Activate
    4. Next
    Last edited by nader; May 3rd, 2011 at 11:37 AM.

  2. #2
    Hyperactive Member
    Join Date
    Oct 2010
    Location
    Indiana
    Posts
    457

    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???

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How can I make find properties from workbook to another workbooks?

    if the workbooks are already open
    vb Code:
    1. for each wb in workbooks
    2.   for each wsh in wb.sheets
    3.     'do stuff
    4.   next
    5. 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

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: How can I make find properties from workbook to another workbooks?

    I tried this way and it succeeds with me.
    D
    vb Code:
    1. im wbt As Workbook
    2. Set wbt = Workbooks("tow workbooks")
    3. Dim wk As Workbook
    4. Set wk = Workbooks.Open("C:\wb.xlsx")
    5. For Each wsh In wk.Sheets
    6.    Dim r As Range
    7.  Set r = wsh.Cells.Find(What:=wbt.Sheets(1).TextBox1.Text)
    8.    If Not r Is Nothing Then
    9.            wsh.Activate
    10.            r.Activate
    11.             End If
    12.    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

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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:
    1. set wk = workbooks("wb.xlsx")

    try like this to find if workbook is already open, or open if not
    vb Code:
    1. dim wb as workbook
    2. for each wb in workbooks
    3.   if wb.name = "wb.xlsx" then exit for
    4. next
    5. 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

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    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
  •  



Click Here to Expand Forum to Full Width