vba 从 Outlook 宏运行 Excel 宏出现错误 1004
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20187276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running Excel macro from Outlook macro getting error 1004
提问by user3016795
I have a rule in Outlook which is running a VBA script. This VBA is to open a local Excel file, and run the macro in the Excel file.
我在 Outlook 中有一个运行 VBA 脚本的规则。这个VBA是打开本地的Excel文件,运行Excel文件中的宏。
When running, and opening the Excel file, I'm getting the error: Run-time error 1004: Cannot run the macro 'Ask me question workflow.xlsm!AskMeFlow'. The macro may not be available in this workbook or all macros may be disabled.
运行并打开 Excel 文件时,出现错误:运行时错误 1004:无法运行宏“向我提问工作流.xlsm!AskMeFlow”。宏在此工作簿中可能不可用,或者可能禁用了所有宏。
When running the Excel macro from Excel, all is running fine.
从 Excel 运行 Excel 宏时,一切正常。
My code in Outlook:
我在 Outlook 中的代码:
Sub AskMeAlerts()
Dim appExcel As Excel.Application
Dim wkb As Excel.Workbook
Set appExcel = CreateObject("Excel.Application")
appExcel.Workbooks.Open ("C:\Ask me question workflow.xlsm")
appExcel.Visible = True
appExcel.Run "Ask me question workflow.xlsm!AskMeFlow"
appExcel.ActiveWorkbook.Close
appExcel.Quit
Set appExcel = Nothing
Set wkb = Nothing
End Sub
回答by Jean-Fran?ois Corbett
You have to surround the workbook name in '
single quotes:
您必须用'
单引号将工作簿名称括起来:
appExcel.Run "'Ask me question workflow.xlsm'!AskMeFlow"
You can get away without the '
single quotes when your workbook name doesn't contain spaces, but yours does.
'
当您的工作簿名称不包含空格时,您可以在没有单引号的情况下离开,但您的工作簿名称包含空格。
回答by user3710965
Outlook 2010 running Excel 2010 macros seems to need the single quotes (see earlier answer) even if the workbook name doesn't contain spaces. What worked in Office 2003 wouldn't work in 2010 without them.
即使工作簿名称不包含空格,运行 Excel 2010 宏的 Outlook 2010 似乎也需要单引号(请参阅前面的答案)。如果没有它们,在 Office 2003 中起作用的东西在 2010 年将不起作用。