如何使用powerpoint在VBA中打开excel前景
我正试图在PowerPoint演示文稿中打开一个Excel文件。 这是我的代码:
Sub diversestickersKoole() Dim xlApp As Object Dim xlWorkBook As Object Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True Set xlWorkBook = xlApp.Workbooks.Open("V:\Oliedocs\Koole\Stickers Scheepstanks Koole.xltm", True, False) Set xlApp = Nothing Set xlWorkBook = Nothing End Sub
excel文件在后台打开。 这必须在前台。
有人能帮我吗?
添加行xlWorkBook.Activate应该是足够的。
你的代码应该是这样的:
Sub diversestickersKoole() Dim xlApp As Object Dim xlWorkBook As Object Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True Set xlWorkBook = xlApp.Workbooks.Open("V:\Oliedocs\Koole\Stickers Scheepstanks Koole.xltm", True, False) xlWorkBook.Activate Set xlApp = Nothing Set xlWorkBook = Nothing End Function
供参考:
邮政#4
你可以使用AppActivate
。
下面的代码使用“test.xlsx – Excel,因为这是我的testing工作簿的标题。
贴纸Scheepstanks Koole.xltm – Excel应该为你工作
Sub diversestickersKoole() Dim xlApp As Object Dim xlWorkBook As Object Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True 'Set xlWorkBook = xlApp.Workbooks.Open("V:\Oliedocs\Koole\Stickers Scheepstanks Koole.xltm", True, False) Set xlWorkBook = xlApp.Workbooks.Open("C:\temp\test.xlsx", True, False) AppActivate "test.xlsx - Excel" Set xlApp = Nothing Set xlWorkBook = Nothing End Sub
因为你似乎对保持Excel对象及其派生的对象不感兴趣,所以你可能想要像下面的代码
Sub diversestickersKoole() With CreateObject("Excel.Application") '<--| create a new Excel instance and reference it (all its derived objects will be reached by a 'dot') .Visible = True .WindowState = -4137 '<--| maximize Excel window .Workbooks.Open("V:\Oliedocs\Koole\Stickers Scheepstanks Koole.xltm", True, False).Activate End With End Sub