我需要取消隐藏打开的xlsx文件的表TAB,因此,要使用VBS文件打开xlsm文件并激活宏(位于模块中)。 当我手动运行宏时,它可以工作。 通过vbs激活时,只能看到包含该宏的xlsm文件,此刻看不到其他打开的excel。
有什么想法吗?
vbs代码:
Set objExcel = CreateObject("Excel.Application")
Set book = objExcel.Workbooks.Open("C:\Users\23892\Desktop\restore_ribbon.xlsm")
objExcel.Application.Run "'C:\Users\23892\Desktop\restore_ribbon.xlsm'!Module1.Restore_Ribbons"
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
宏代码:
Sub Restore_Ribbons()
Dim wb As Workbook
Dim str As String
For Each wb In Application.Workbooks
MsgBox wb.Name 'checking if name extracted correctly
wb.Activate
Application.ScreenUpdating = False
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"
ActiveWindow.DisplayWorkbookTabs = True
wb.Application.ScreenUpdating = True
Next Workbook
MsgBox ("End")
End Sub
答案 0 :(得分:0)
再次输入代码... 然后
Set objExcel = GetObject("C:\restore_ribbon.xlsm")
objExcel.Application.Run "'C:\restore_ribbon.xlsm'!Module1.Restore_Ribbons"
objExcel.Close
Set objExcel = Nothing