Unable to set excel VBA worksheet variable

前端 未结 1 818
闹比i
闹比i 2021-01-26 01:22

I am trying to set a source worksheet variable to a target worksheet variable in another workbook(DataSource1.xlsx) with the purpose of eventually using it to read the target wo

相关标签:
1条回答
  • 2021-01-26 01:50

    If the workbook is already opened, you need to refer to it by name without path:

    Set source = Workbooks("DataSource1.xlsx").Sheets("Sheet1")
    

    If the workbook is not opened yet, you need to open it first:

    Set source = Workbooks.Open(ThisWorkbook.path & "\DataSource1.xlsx").Sheets("Sheet1")
    
    0 讨论(0)
提交回复
热议问题