如何在VBA中使用Powerpoint在前台打开excel
我想在powerpoint演示文稿中打开excel文件。 这是我的代码:如何在VBA中使用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
您链接的示例假定Excel已处于活动状态。 – brettdj
不幸的是它不起作用:( –
您可以使用AppActivate
。
下面的代码使用“test.xlsx - Excel中因为这是我的测试工作簿的标题
贴纸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
不幸的是这不起作用,excel文件在后台打开。 –
不应该是End Sub而不是End Function?代码在演示文稿顶部打开工作簿。有什么问题? – sktneer