如何在Excel中使用VBA代码更新pdf文件中的Excel数据?

时间:2019-06-13 11:00:55

标签: excel vba pdf-extraction

我想通过以下代码在现有的PDF中添加excel单元格值。请任何人帮助我在Ex代码中调用“ UpdateValue”变量,以便excel值可以pdf打印。

我也尝试过使用表单,但是没有用。

Sub Update_values()
        Dim Path, FileName, FilePath
        Dim avdoc As CAcroAVDoc
        Dim jso As Object
        Dim PDDoc As CAcroPDDoc


        FilePath = "C:\New folder\A.pdf"

        Set Acroapp = CreateObject("AcroExch.App")
        Set PDDoc = CreateObject("AcroExch.PDDoc")
        Set App = CreateObject("Acroexch.App")
        Acroapp.Show
        Set avdoc = CreateObject("AcroExch.AVDoc")
        Set AForm = CreateObject("AFormAut.App") 'from AFormAPI
        UpdateValue = Range("A2").Value

        If avdoc.Open(FilePath, "") Then


         Ex = "  var Box2Width = 50  " & vbLf _
          & "  for (var p = 0; p < this.numPages; p++)   " & vbLf _
          & "   {var aRect = this.getPageBox(""Crop"",p);  " & vbLf _
          & "    var TotWidth = aRect[2] - aRect[0]  " & vbLf _
          & "     {  var bStart=(TotWidth/2)-(Box2Width/2)  " & vbLf _
          & "         var bEnd=((TotWidth/2)+(Box2Width/2))  " & vbLf _
          & "         var fp = this.addField(String(""xftPage""+p+1), ""text"", 0, [180,830,10,600]);   " & vbLf _
          & "         fp.value =  UpdateValue  " & vbLf _
          & "         fp.textSize=7;  fp.readonly = true;  " & vbLf _
          & "         fp.alignment=""center"";  " & vbLf _
          & "     }  " & vbLf _
          & "   }  "

        AForm.Fields.ExecuteThisJavaScript Ex
        End If

        Set avdoc = Nothing
        Set App = Nothing
        Set AForm = Nothing


End Sub

0 个答案:

没有答案