通过Visual Basic在Word中设置包括PDF文件在内的属性



我在Word中编辑了一个现有的Visual Basic宏,这样我就可以在Word中以OLEObject的形式插入PDF文档。现在的问题是,PDF文件没有以其原始格式插入,所以我想调整大小/保持其原始格式。

我目前使用的代码是:

Public Sub VervangTekstDoorLogo()
'
' VervangTekstDoorLogo Macro
'
'

   If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
        ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
        ActivePane.View.Type = wdOutlineView Then
        ActiveWindow.ActivePane.View.Type = wdPrintView
    End If
    ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Selection.TypeText Text:="<briefpapier>"
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "<briefpapier>"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute

    Dim LogoBestandKop As String
    Dim LogoBestandVoet As String
    LogoBestandKop = "c:Document.PDF"

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "<briefpapier>"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue

    End With

    Do While Selection.Find.Execute
      With Selection.InlineShapes.AddOLEObject(FileName:=LogoBestandKop, LinkToFile:=False)
          End With

            ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
            Selection.EscapeKey

 Loop
   'Selection.Find.Execute Replace:=wdReplaceAll
   'Selection.Find.Execute Replace:=wdReplaceAll
   'ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.InlineShapes.AddOLEObject LogoBestandKop
End Sub

有人能告诉我如何强制宏保持原始PDF大小吗?我知道设置图片对象的属性很热门,只是不适合OLEObjects。

您插入Word的任何对象都将自动调整大小,以适应可用的"文本框"——在表格单元格内、文本框内、页面边距内。您可以尝试将页边距设置为0,假设原始PDF的大小与要插入的文档的页面大小相匹配。

但请注意,如果PDF文档包含多个页面,则不能强制OLE对象显示所有页面。OLE容器不能以这种方式工作——在相关联的OLE服务器打开对象之前,它们只能显示一个页面。

最新更新