These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

vb script

rpreiss
Registered: Jul 5 2007
Posts: 6

I am a new user trying to use this VB script and am getting the following error: "Expected end of Satement" what am I doing wrong. Thanks for any help.
 
Option Explicit ' Force variable declaration
  
Public Const PDF_WILDCARD = "*.pdf"
Public Const PDF_DIRECTORY = "c:\acrobatdocstomerge\"
Public Const JOIN_FILENAME = "complete.pdf"
 
Sub JoinAllAcrobatDocsInDir()
  
Dim AcroExchApp As Object
Dim AcroExchPDDoc As Object
Dim AcroExchInsertPDDoc As Object
Dim strFileName As String, strPath As String
Dim iNumberOfPagesToInsert As Integer
Dim iLastPage As Integer
 
Set AcroExchApp = CreateObject("AcroExch.App")
Set AcroExchPDDoc = CreateObject("AcroExch.PDDoc")
 
' Show the Acrobat Exchange window
AcroExchApp.Show
 
' Set the directory / folder to use
strPath = PDF_DIRECTORY
 
' Get the first pdf file in the directory
strFileName = Dir(strPath + PDF_WILDCARD, vbNormal)
 
' Open the first file in the directory
AcroExchPDDoc.Open strPath + strFileName
 
' Get the name of the next file in the directory [if any]
If strFileName "" Then
strFileName = Dir
 
' Start the loop.
Do While strFileName ""
' Get the total pages less one for the last page num [zero based]
iLastPage = AcroExchPDDoc.GetNumPages - 1
 
Set AcroExchInsertPDDoc = CreateObject("AcroExch.PDDoc")
 
' Open the file to insert
AcroExchInsertPDDoc.Open strPath + strFileName
 
' Get the number of pages to insert
iNumberOfPagesToInsert = AcroExchInsertPDDoc.GetNumPages
 
' Insert the pages
AcroExchPDDoc.InsertPages iLastPage, AcroExchInsertPDDoc, 0, iNumberOfPagesToInsert, True
 
' Close the document
AcroExchInsertPDDoc.Close
 
' Get the name of the next file in the directory
strFileName = Dir
Loop
 
' Save the entire document as the JOIN_FILENAME using SaveFull [0x0001 = &H1]
AcroExchPDDoc.Save &H1, strPath + JOIN_FILENAME
 
End If
 
' Close the PDDoc
AcroExchPDDoc.Close
 
' Close Acrobat Exchange
AcroExchApp.Exit
End Sub

My Product Information:
Acrobat Pro 8, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
This is a Visual Basic error that has nothing to do with Acrobat.

Did you look it up in the VB Documentation? or on line?

[url=http://www.computerperformance.co.uk/Logon/code/code_800A0401.htm]http://www.computerperformance.co.uk/Logon/code/code_800A0401.htm[/url]

What line does the error occur on?

Please indent your code when you post it so that we can read it.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Mr.Jiggs
Registered: Apr 11 2006
Posts: 39
If strFileName "" Then

should be

If strFileName = "" Then

and

Do While strFileName ""

should be

Do While strFileName = ""

give that a try...

Mr. Jiggs

Mr. Jiggs

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Thank you Mister Jiggs!!

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Mr.Jiggs
Registered: Apr 11 2006
Posts: 39
I did this in VB6, so it uses:

Private Sub Command1_Click()

where you use:

Sub JoinAllAcrobatDocsInDir()

It appears you're doing you tests backwards. You want to make sure that strFileName is NOT blank !
Try the following:

Option Explicit ' Force variable declaration

Const PDF_WILDCARD = "*.pdf"
Const PDF_DIRECTORY = "c:\acrobatdocstomerge\"
Const JOIN_FILENAME = "complete.pdf"

Private Sub Command1_Click()
'Sub main()
Dim AcroExchApp As Object
Dim AcroExchPDDoc As Object
Dim AcroExchInsertPDDoc As Object
Dim strFileName As String, strPath As String
Dim iNumberOfPagesToInsert As Integer
Dim iLastPage As Integer

Set AcroExchApp = CreateObject("AcroExch.App")
Set AcroExchPDDoc = CreateObject("AcroExch.PDDoc")

' Show the Acrobat Exchange window
AcroExchApp.Show

' Set the directory / folder to use
strPath = PDF_DIRECTORY

' Get the first pdf file in the directory
Dim fileSearch As String
fileSearch = strPath & PDF_WILDCARDstrFileName = Dir(fileSearch)

' Open the first file in the directory
AcroExchPDDoc.Open strPath + strFileName

' Get the name of the next file in the directory [if any]
If Not strFileName = "" Then
strFileName = Dir

' Start the loop.
Do While Len(strFileName) > 0
' Get the total pages less one for the last page num [zero based]
iLastPage = AcroExchPDDoc.GetNumPages - 1

Set AcroExchInsertPDDoc = CreateObject("AcroExch.PDDoc")

' Open the file to insert
AcroExchInsertPDDoc.Open strPath + strFileName

' Get the number of pages to insert
iNumberOfPagesToInsert = AcroExchInsertPDDoc.GetNumPages

' Insert the pages
AcroExchPDDoc.InsertPages iLastPage, AcroExchInsertPDDoc, 0, iNumberOfPagesToInsert, True

' Close the document
AcroExchInsertPDDoc.Close

' Get the name of the next file in the directory
strFileName = Dir
Loop

' Save the entire document as the JOIN_FILENAME using SaveFull [0x0001 = &H1]
AcroExchPDDoc.Save &H1, strPath + JOIN_FILENAMEEnd If

' Close the PDDoc
AcroExchPDDoc.Close

' Close Acrobat Exchange
AcroExchApp.Exit
End Sub

Mr. Jiggs

Mr. Jiggs

Mr.Jiggs
Registered: Apr 11 2006
Posts: 39
Hey Thom, the code I just posted was indented in this box, but all the formatting is thrown away upon posting. How would you maintain the formatting ?

Mr. Jiggs

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Try using [b]BBCode[/b]. I don't know if it will work in the comments so here's a test.

if(this and that){This line is indented.This one is indented more}

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

davesawyer (not verified)
Hello,

We have updated the commenting functionality. Line breaks are now maintained. You can also use [url=javascript:openPopWindow('/help/bbcode_formatting.php','','scrollbars=yes,resizable=yes,width=625,height=550')]BBCode[/url] to format your comments.

-Dave Sawyer
Acrobat User Community Support

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Thank you Dave!!! You're the man:)

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script