如何使用powerpoint

时间:2017-04-03 06:39:17

标签: excel powerpoint powerpoint-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文件在后台打开。这必须在前台。

有人可以帮助我吗?

3 个答案:

答案 0 :(得分:0)

添加xlWorkBook.Activate行就足够了。

您的代码应如下所示:

access_token = request.POST.get("access_token")

供参考:

https://www.mrexcel.com/forum/excel-questions/670476-excel-visual-basic-applications-test-if-workbook-open-if-so-bring-front.html

发布#4

答案 1 :(得分:0)

您可以使用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

答案 2 :(得分:0)

因为您似乎对保留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