上次更新:2019 年 4 月 10 日
問題
Mac 版 Excel 在 2017 年 10 月推出新版 Visual Basic 編輯器。 使用新版 Visual Basic 編輯器時,如果從程式碼視窗頂端的下拉式功能表中選擇選項,會發生建立物件宣告的問題。
如果您按一下左側的下拉式清單,然後從清單中選擇一個項目,您應該會在右側的下拉式清單中得到所選活動的部分程式碼。 您可以從右側的下拉式清單中選取其他項目,來建立額外的程式碼以處理所選活動。
但此時會發生無法建立程式碼的問題。
狀態:因應措施
請選擇下列其中一個因應措施來解決此問題:
因應措施 #1
在執行 Windows 版 Excel 的電腦上執行類似步驟,然後將程式碼複製到 Mac 版 Excel。
因應措施 #2
移至 MSDN 並尋找您要使用之活動的語法,然後手動將程式碼輸入到 VBA 專案。 本文說明 Microsoft Excel「活頁簿」活動 - 活頁簿活動 (機器翻譯)。
因應措施 #3
從以下範例中複製適當的活動程式碼,並貼到 VBA 專案。 請務必針對每個活動複製 "Private Sub..." 到 "End Sub" (含) 之間的程式碼。
Private Sub Workbook_Activate()
End SubPrivate Sub Workbook_AddinInstall()
End SubPrivate Sub Workbook_AddinUninstall()
End SubPrivate Sub Workbook_AfterRemoteChange()
End SubPrivate Sub Workbook_AfterSave(ByVal Success As Boolean)
End SubPrivate Sub Workbook_BeforeClose(Cancel As Boolean)
End SubPrivate Sub Workbook_BeforePrint(Cancel As Boolean)
End SubPrivate Sub Workbook_BeforeRemoteChange()
End SubPrivate Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
End SubPrivate Sub Workbook_Deactivate()
End SubPrivate Sub Workbook_NewChart(ByVal Ch As Chart)
End SubPrivate Sub Workbook_NewSheet(ByVal Sh As Object)
End SubPrivate Sub Workbook_Open()
End SubPrivate Sub Workbook_PivotTableCloseConnection(ByVal Target As PivotTable)
End SubPrivate Sub Workbook_PivotTableOpenConnection(ByVal Target As PivotTable)
End SubPrivate Sub Workbook_RowsetComplete(ByVal Description As String, ByVal Sheet As String, ByVal Success As Boolean)
End SubPrivate Sub Workbook_SheetActivate(ByVal Sh As Object)
End SubPrivate Sub Workbook_SheetBeforeDelete(ByVal Sh As Object)
End SubPrivate Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
End SubPrivate Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
End SubPrivate Sub Workbook_SheetCalculate(ByVal Sh As Object)
End SubPrivate Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
End SubPrivate Sub Workbook_SheetDeactivate(ByVal Sh As Object)
End SubPrivate Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink)
End SubPrivate Sub Workbook_SheetPivotTableAfterValueChange(ByVal Sh As Object, ByVal TargetPivotTable As PivotTable, ByVal TargetRange As Range)
End SubPrivate Sub Workbook_SheetPivotTableBeforeAllocateChanges(ByVal Sh As Object, ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long, Cancel As Boolean)
End SubPrivate Sub Workbook_SheetPivotTableBeforeCommitChanges(ByVal Sh As Object, ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long, Cancel As Boolean)
End SubPrivate Sub Workbook_SheetPivotTableBeforeDiscardChanges(ByVal Sh As Object, ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long)
End SubPrivate Sub Workbook_SheetPivotTableChangeSync(ByVal Sh As Object, ByVal Target As PivotTable)
End SubPrivate Sub Workbook_SheetPivotTableUpdate(ByVal Sh As Object, ByVal Target As PivotTable)
End SubPrivate Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
End SubPrivate Sub Workbook_SheetTableUpdate(ByVal Sh As Object, ByVal Target As TableObject)
End SubPrivate Sub Workbook_Sync(ByVal SyncEventType As Office.MsoSyncEventType)
End SubPrivate Sub Workbook_WindowActivate(ByVal Wn As Window)
End SubPrivate Sub Workbook_WindowDeactivate(ByVal Wn As Window)
End SubPrivate Sub Workbook_WindowResize(ByVal Wn As Window)
End SubPrivate Sub Worksheet_Activate()
End Sub
Private Sub Worksheet_BeforeDelete()
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
End Sub
Private Sub Worksheet_Calculate()
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
End Sub
Private Sub Worksheet_Deactivate()
End Sub
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
End Sub
Private Sub Worksheet_LensGalleryRenderComplete()
End Sub
Private Sub Worksheet_PivotTableAfterValueChange(ByVal TargetPivotTable As PivotTable, ByVal TargetRange As Range)
End Sub
Private Sub Worksheet_PivotTableBeforeAllocateChanges(ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long, Cancel As Boolean)
End Sub
Private Sub Worksheet_PivotTableBeforeCommitChanges(ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long, Cancel As Boolean)
End Sub
Private Sub Worksheet_PivotTableBeforeDiscardChanges(ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long)
End Sub
Private Sub Worksheet_PivotTableChangeSync(ByVal Target As PivotTable)
End Sub
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub
Private Sub Worksheet_TableUpdate(ByVal Target As TableObject)
End Sub