如何在另一个工作簿中引用工作簿以自动打开文件?

时间:2016-06-20 18:23:27

标签: excel vba excel-vba

我有一个工作簿,其中包含用于运行宏的命令按钮。我希望将工作簿3的文件路径保存在单元格B17中命令按钮下面的工作表中。我希望下面的宏引用该单元格并自动打开工作簿3.文件路径将每天更改,我不想在开发人员选项卡中更改它。请帮忙!

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

1 个答案:

答案 0 :(得分:2)

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