VBA Macro workbook.open or workbook.activate through variable reference

前端 未结 2 1913
忘了有多久
忘了有多久 2021-01-25 19:56

How do I reference my primary workbook and the second workbook I open through this sub procedure? I attempt to do workbooks.(\"client_path\").activate as my goal wi

相关标签:
2条回答
  • 2021-01-25 20:20
    dim Wb as workbook
    
    set wb= Workbooks.Open (Client_path).activate
    

    this opens, and activates it all in one line, an sets a variable for later use (wb).

    note that refering later to wb will NOT open it again, and NOT activate it again, its just reference to the wb ! (unless you tell him to)

    0 讨论(0)
  • 2021-01-25 20:24

    Can you just make references to your workbook earlier?

    Dim wb as workbook
    Dim wbDirty as workbook
    
    set wb = thisWorkbook
    set wbDirty = workbooks.open Client_Path
    

    Then when you define the ranges, Excel knows which workbook they belong to.

    Dim rngReconcile as range
    Dim rngWatch as range
    
    set rngReconcile = wb.Sheets(1).Range("K:K")
    set rngWatch = wbDirty.Sheets("Client DIRTY watchlist").Range("B:B")
    

    Then continue on with your looping code

    0 讨论(0)
提交回复
热议问题