excel - 从外部 vbs 运行时宏的行为不同
问题描述
我需要为打开的 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
解决方案
再次输入代码......再次感谢
Set objExcel = GetObject("C:\restore_ribbon.xlsm")
objExcel.Application.Run "'C:\restore_ribbon.xlsm'!Module1.Restore_Ribbons"
objExcel.Close
Set objExcel = Nothing
推荐阅读
- unity3d - Unity3d ProBuilder Spheres 导致高延迟?
- automated-tests - 在 Appium 中连接 XCAutomation 失败
- android - Android构建错误:无法获取'https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2/4.0.2-6197926/aapt2-4.0.2-6197926-osx。罐'
- git - 为什么 .gitignore 会在 pull 期间下载文件并在修改时产生冲突?
- macos - 使用 AppleScript / JXA 在 Apple Mail 中获取电子邮件 URL
- docker - XDebug 无法从 docker 容器连接到客户端
- android - 如何在android kotlin中检查手电筒是否打开
- java - 如何让用户在运行时为 Spring-data-JPA 选择数据库
- error-handling - Fastled没有足够的CPU能力?
- reactjs - 我无法在 MS Edge 的输入字段中将文本居中对齐