我正在尝试创建一个在打开工作簿时运行的代码。我尝试使用 Auto_open 和 workbook_open(在 ThisWorkbook 对象内)但我对它们都有问题。问题是代码需要我正在打开的工作簿中的信息正如您在这段代码中看到的那样:
Sub Auto_Open()
Dim fileNam As String
Dim text As String
Dim answer As String
Dim question As String
Dim quesPos As Integer
MsgBox "add-in start"
'On Error GoTo GetOut
fileNam = ThisWorkbook.FullName
jsonFile = Replace(jsonFile, "xls", "survey.descriptor.json")
Open jsonFile For Input As #2
pos = 1
ThisWorkbook.Sheets("Result").Select
'The code gives the error here
由于 excel 文件尚未打开,因此在获取文件名时会出错。如何在打开代码但打开后执行代码?