Private Sub 登场1_Click()
Dim xlsApp As Excel.Application
Dim xlsWorkbook As Excel.Workbook
Dim xlssheet As Excel.Worksheet
Set xlsApp = CreateObject("Excel.Application") '新建Excel对象
Set xlsWorkbook = xlsApp.Workbooks.Open(App.Path & "\data.xlsx") '打开EXCEL工作簿
Set xlssheet = xlsWorkbook.Worksheets(1) '打开EXCEL工作表
Set X = CreateObject("scripting.dictionary")
Set Y = CreateObject("scripting.dictionary")
Set X = Sheets("Level").Range("A1:AE1").Cells.Find("关卡.ChapterLabel").Row
'这里关卡.ChapterLabel作为一个变量,想在EXCEL中找到对应这个值的X轴对应坐标
Set Y = Sheets("Level").Range("A2:A61").Cells.Find("关卡.登场1.Caption").Column
'这里关卡.登场1.Caption作为一个变量,想在EXCEL中找到对应这个值的Y轴对应坐标
If 关卡.登场1.Caption = xlsApp.Range("B2").Value Then
角色.LevelLabel2 = xlsApp.Cells(X, Y)
ElseIf 关卡.登场1.Caption = xlsApp.Range("B3").Value Then
角色.LevelLabel2 = xlsApp.Cells(X, Y)
End If
xlsWorkbook.Close SaveChanges:=False
xlsApp.Quit
Set xlsWorkbook = Nothing
Set xlssheet = Nothing
Set xlsApp = Nothing '释放Excel对象
End Sub
以上代码输入后一直说:
“实时错误:91”
“对象变量或with块变量未设置”
求问如何解决?
Dim xlsApp As Excel.Application
Dim xlsWorkbook As Excel.Workbook
Dim xlssheet As Excel.Worksheet
Set xlsApp = CreateObject("Excel.Application") '新建Excel对象
Set xlsWorkbook = xlsApp.Workbooks.Open(App.Path & "\data.xlsx") '打开EXCEL工作簿
Set xlssheet = xlsWorkbook.Worksheets(1) '打开EXCEL工作表
Set X = CreateObject("scripting.dictionary")
Set Y = CreateObject("scripting.dictionary")
Set X = Sheets("Level").Range("A1:AE1").Cells.Find("关卡.ChapterLabel").Row
'这里关卡.ChapterLabel作为一个变量,想在EXCEL中找到对应这个值的X轴对应坐标
Set Y = Sheets("Level").Range("A2:A61").Cells.Find("关卡.登场1.Caption").Column
'这里关卡.登场1.Caption作为一个变量,想在EXCEL中找到对应这个值的Y轴对应坐标
If 关卡.登场1.Caption = xlsApp.Range("B2").Value Then
角色.LevelLabel2 = xlsApp.Cells(X, Y)
ElseIf 关卡.登场1.Caption = xlsApp.Range("B3").Value Then
角色.LevelLabel2 = xlsApp.Cells(X, Y)
End If
xlsWorkbook.Close SaveChanges:=False
xlsApp.Quit
Set xlsWorkbook = Nothing
Set xlssheet = Nothing
Set xlsApp = Nothing '释放Excel对象
End Sub
以上代码输入后一直说:
“实时错误:91”
“对象变量或with块变量未设置”
求问如何解决?