0
我在Outlook中有一个宏,我打开一个保存在桌面上的Excel文件。一旦文件打开,我想运行一个我用excel编写的宏,但是我的excel宏都不可用。无论何时我以其他方式打开excel,宏都可用,并且在通过outlook vba打开excel时启用宏。我的问题是,当我通过Outlook宏打开Excel时,如何使这些宏可用?请参考下面的代码。当从Outlook宏打开Excel时,不存在现有的宏
'Pre:None
'Post:Excel will have been opened, and the macro "CreatePowerPoint()"
' will have been run on the excel document
Sub Gimba()
Dim xlApp As Object, xlWkb As Object
'open excel
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True ' can be False if you do not wont see reaction,
' byt make sure is not fail
'Do not show any alerts
xlApp.DisplayAlerts = False
'open excel document
Set xlWkb = xlApp.Workbooks.Open(file path goes here)
'call macro on excel document
Call xlApp.Run("CreatePowerPoint")
End Sub
'CreateObject'与绑定无关。他将不得不引用对象库,然后声明xlApp对象'As Excel.Application'。他仍然可以使用'CreateObject'。 – JimmyPena 2013-05-20 20:47:08
但是,如果您使用CreateObject,则在使用New语句时不会获得智能感知帮助,这是评论的要点 – steveo40 2013-05-21 10:16:03
您需要从实例化中分离绑定。当您在声明对象时使用'New'关键字时,无论您如何实例化对象,您都会在该行和后续行上获得Intellisense。试试看看。 – JimmyPena 2013-05-22 20:10:41