gpt4 book ai didi

excel - 在存储在另一个文件中的 CSV 文件上运行宏

转载 作者:行者123 更新时间:2023-12-04 22:31:15 25 4
gpt4 key购买 nike

我有一个每天收到的 CSV 文件,我使用存储在我的个人宏文件中的宏对其进行格式化。我正在尝试创建一个 vbs 文件,该文件将通过计划任务在 CSV 文件上运行宏,但我没有运气。这是vbs文件:

Option Explicit

ExcelMacroExample

Sub ExcelMacroExample()
Dim xlApp
Dim xlBook

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("c:\users\dmcgettigan\desktop\test.csv", 0, True)
xlApp.Run "c:\users\dmcgettigan\desktop\Personal.xlsb!newsales"
xlApp.Quit

Set xlBook = Nothing
Set xlApp = Nothing
End Sub

这是我得到的错误:

C:\Users\dmcgettigan\Desktop\test.vbs(13, 3) Microsoft Excel: Cannot run the macro 'c:\users\dmcgettigan\desktop\Personal.xlsb!new sales'. The macro may not be available in this workbook or all macros may be disabled.



关于我做错了什么的任何想法?

最佳答案

对我来说,它就是这样工作的

  Dim xlApp 

Set xlApp = CreateObject("Excel.Application")
xlapp.workbooks.open("<Path to your PERSONAL.XLSB>")
xlApp.Run "PERSONAL.XLSB!Test"
xlApp.Quit

评论也对,你要运行的子名称不能有空格。

更新 如果无法对其进行测试,您的代码应该如下所示
Option Explicit

ExcelMacroExample

Sub ExcelMacroExample()
Dim xlApp
Dim xlBook

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("c:\users\dmcgettigan\desktop\test.csv", 0, True)
xlapp.workbooks.open("c:\users\dmcgettigan\desktop\Personal.xlsb")
xlApp.Run "Personal.xlsb!newsales"
xlApp.Quit

Set xlBook = Nothing
Set xlApp = Nothing
End Sub

关于excel - 在存储在另一个文件中的 CSV 文件上运行宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52607389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com