|
各位大大,请教一下,我在VBA中调用JS的时候,发生一件很神奇的事情。以下是详细说明:
背景: 我想用VBA在PDF中加入页码以及一个工单号码(就是这个变量wo).
问题描述:
a) 当我在代码中写
wo = "1234"
可以成功执行,页脚中会显示 pages 1/5 WO ID:1234.
b) 当我在代码中写
wo = "A1234"
这个页脚中就是一片空白,什么内容也没有。
----以下是代码---------------------------
Sub addpdfpage()
'add pdf page numbers
Dim pddoc As Acrobat.CAcroPDDoc
Dim wo As String
wo = "A1234"
Path = "D:\Destination.pdf"
Set App = CreateObject("Acroexch.app")
'APP.Show
Set AVDOC = CreateObject("AcroExch.AVDoc")
Set AForm = CreateObject("AFormAut.App") 'from AFormAPI
If AVDOC.Open(Path, "") Then
'//write JS-Code on a variable
MsgBox wo
Ex = " // Set Footer PageNo centered " & vbLf _
& " var Box2Width = 500 " & vbLf _
& " var wo1 = " + wo + " " & vbLf _
& " for (var p = 0; p < this.numPages; p++) " & vbLf _
& " { " & 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"", p, [bStart,30,bEnd,15]); " & vbLf _
& " fp.value = ""Page: "" + String(p+1)+ ""/"" + this.numPages + "" WO ID"" + wo1 ; " & vbLf _
& " fp.textSize=6; fp.readonly = true; " & vbLf _
& " fp.alignment=""center""; " & vbLf _
& " } " & vbLf _
& " } "
'//Execute JS-Code
AForm.Fields.ExecuteThisJavaScript Ex
' MsgBox ("Done")
End If
Set pddoc = AVDOC.GetPDDoc
pddoc.Save 1, "D:\Destination.pdf"
'MsgBox ("Done11")
AVDOC.Close (ture)
Set pddoc = Nothing
Set AVDOC = Nothing
Set App = Nothing
End Sub
-------------以上是代码------------------
|
|