简体   繁体   中英

How can I find the Word object which is opened by VBA in Excel?

I have an Excel file with a VBA script to export data from Excel to PDF. As a step in between the Excel data and the pdf there is a Word document which provides the layout of the pdf.

I would like to change the layout of the Word document. I know that the file or reference in VBA is called LogboekBMI but I can't find it.

I have the feeling there is a hidden object somewhere in the Excel worksheets.

'Word document naar pdf omzetten (logboek)
Logboek.Shapes("LogboekBMI").OLEFormat.Activate
Set objWord = Logboek.Shapes("LogboekBMI").OLEFormat.Object.Object

objWord.ExportAsFixedFormat _
        OutputFileName:=strLogboek, _
        ExportFormat:=17, _
        OpenAfterExport:=False, _
        OptimizeFor:=0, _
        Range:=0, _
        From:=1, To:=1, _
        Item:=0, _
        IncludeDocProps:=True, _
        KeepIRM:=True, _
        CreateBookmarks:=0, _
        DocStructureTags:=True, _
        BitmapMissingFonts:=True, _
        UseISO19005_1:=False

objWord.Application.Quit

I would guess that Logboek is the code name for a sheet object in your workboook. You can confirm this by looking at the list of sheets in the VBA project explorer (Ctrl + R if it isn't visible in the VBA window). You could use code like this to select the shape it is referring to. The shape seems to contain an OLE embedded version of the Word document.

Logboek.Visible = xlSheetVisible
Logboek.Activate
Logboek.Shapes("LogboekBMI").Visible = True
Logboek.Shapes("LogboekBMI").Select

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM