简体   繁体   中英

How can I reference a workbook within another workbook to automatically open the file?

I have a workbook that contains command buttons to run the macro. I want the file path for Workbook 3 to be saved in the worksheet underneath the command button in cell B17. I want the macro below to reference that cell and automatically open Workbook 3. The file path will change everyday and I do not want to have to change it in the developer tab. Please help!

Sub NCFinal()

Dim Wb1 As Workbook
Dim Wb2 As Workbook
Dim Wb3 As Workbook

With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
End With

Set Wb1 = Workbooks.Open("A:Desktop\Excel Files\Data Template.xlsb")
Set Wb2 = Workbooks.Open("A:Desktop\Excel Files\MarchData.xlsb")
**Set Wb3 = Workbooks.Open(Filename:=Sheets("Sheet1").Range("B17").Value)**
Wb1.Sheets("FRD").Copy After:=Wb2.Sheets("Sheet1")
Wb3.Sheets("CDGL Data").Copy After:=Wb2.Sheets("FRD")

Wb1.Close False
Wb3.Close False
Set Wb3 = Workbooks.Open(Filename:=ThisWorkbook.Sheets("Sheet1").Range("B17").Value)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM