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

前端 未结 2 1912
忘了有多久
忘了有多久 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条回答
  •  梦毁少年i
    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

提交回复
热议问题