我創建了Excel的加載項,它確定了ActiveSheet
和ActiveWorkbook
的名稱。我使用的代碼如下。當我運行加載項時,它在消息框「變量集」之後顯示上述錯誤。但是當我在宏中運行它時,它工作正常。我不明白加載項發生了什麼。任何人都可以幫助我嗎?獲取錯誤「對象變量或未設置塊變量」
Sub sheetvalues()
Dim bk As Workbook, sht1 As Worksheet, sht2 As Worksheet, sht3 As Worksheet
Dim book As String, sht As String, i As Integer, j As Integer
Dim att(1 To 4) As String, att_col(1 To 4) As Integer
MsgBox ("variables set")
book = ActiveWorkbook.Name
sht = ActiveSheet.Name
MsgBox ("names set")
Set bk = Workbooks.Add
With bk
.Title = "MissingValues"
.SaveAs Filename:="MissingValues.xls"
End With
Set sht1 = bk.Sheets.Add
sht1.Name = "EndOne"
Set sht2 = bk.Sheets.Add
sht2.Name = "EndTwo"
Set sht3 = bk.Sheets.Add
sht3.Name = "EndThree"
MsgBox (book & " " & sht)
MsgBox ("completed")
End Sub
您是否正在打開工作簿上的加載項運行? – Ripster
如果您的加載項是加載的唯一工作簿,則可能沒有ActiveWorkbook ... –