Acrobat AddNewAnnot SetContents失败

时间:2016-12-19 15:31:44

标签: vba excel-vba pdf acrobat excel

我想用vba将新的FreeText评论添加到PDF文件中。

Public Sub AddAnnot(Page As Object, Text As String)
Dim Rect As Object, Annot As Object
Set Rect = CreateObject("AcroExch.Rect")
Dim Space As Integer, Height As Integer
Space = 0
Height = 15
With Rect
    .bottom = Space
    .Left = Space
    .Right = Page.GetSize.x - Space
    .Top = Space + Height
End With
Set Annot = Page.AddNewAnnot(0, "FreeText", Rect)
With Annot
    .SetTitle Text
    .SetContents (Text)
    .SetColor RGB(255, 255, 0)
    .SetRect Rect
End With
End Sub

因此,此代码适用于较旧版本的Acrobat,但现在在Acrobat DC中,它始终在.SetContents (Text)行失败并出现简单错误,该方法失败。没关系,它是pdf文件,总是失败。

我做错了什么? 提前致谢

1 个答案:

答案 0 :(得分:0)

对于那些拼命寻找解决方案但却没有找到解决方案的人:在添加Annots的整个过程之前,也将文档作为AVDoc打开。您不必使用它,只需打开即可立即隐藏它。