[英]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. 我希望将工作簿3的文件路径保存在工作表中的单元格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. 我希望下面的宏引用该单元格并自动打开Workbook3。文件路径每天都会更改,并且我不需要在“开发人员”选项卡中进行更改。 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.