从Outlookmacros打开Excel时,不存在现有的macros

我在Outlook中有一个macros,我打开一个保存在桌面上的Excel文件。 一旦文件被打开,我想运行一个我用excel编写的macros,但是我的excelmacros都不可用。 每当我用其他方式打开excel时,macros都是可用的,并且当我通过outlook vba打开excel时,macros被启用。 我的问题是,当我通过Outlookmacros打开Excel时,如何使这些macros可用? 请参考下面的代码。

'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 

我假设您通常可用的macros存储在您的personal.xls工作簿中? 如果是这样,那么你只需要加载它,然后再尝试启动你的CreatePowerPointmacros。

尝试类似(取决于您的个人工作簿存储在哪里):

 xlApp.Workbooks.Open ("C:\Documents and Settings\YourUserNameHere\Application Data\Microsoft\Excel\XLSTART\personal.xlsb") 

另外,如果使用早期绑定,则可能会发现编写VBA代码更容易。 为此,需要添加对Excel模型的引用,而不是使用CreateObject,可以使用Set xlApp = new Excel.Application。 这样你可以得到Intellitype所有的帮助。