如何通过在VBA中将值传递给variables来打开工作表

我试图通过从一个单元格中取值打开工作表,并连接需要的文件名,但它显示错误:对象variables或块variables未设置我使用以下代码:其中“123.xlsx”是工作簿的名称我想打开。

Dim output_path As Workbook dim xlwkbrpt1 as workbook output_path = Application.ActiveWorkbook.ActiveSheet.Range("F14").Value Set xlwkbrpt1 = xlApp.Workbooks.Open(output_path & "\" & "123.xlsx") 

你用错误的types声明了variablesoutput_path 。 尝试这个:

 Dim output_path As String Dim xlwkbrpt1 As Workbook output_path = Application.ActiveWorkbook.ActiveSheet.Range("F14").Value Set xlwkbrpt1 = Workbooks.Open(output_path & "\" & "123.xls")