Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default close adobe reader window

I'm running the following script to combine multiple pdf files into one using PDFCreator. The problem is when you get to the part where the files are loaded into PDFCreator, Adobe Reader opens (no actual file is opened in it), and the next file will not load into the PDFCreator queue until Adobe Reader is closed. Is there a simple method of closing Adobe Reader in that loop? Or somehow send the pdfs into PDFCreator 'ghostlike' without initiating an instance of Adobe Reader to begin with?

Sub bindPDF()

Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim DefaultPrinter$
Dim bRestart As Boolean
Dim ws As Worksheet, itemrange As Range, cell As Range, itemcount As Integer
Set ws = ActiveSheet
Set itemrange = ws.Range("e1:e18")
Dim sFilenames() As String
For Each cell In itemrange
itemcount = itemcount + 1
ReDim Preserve sFilenames(itemcount - 1)
sFilenames(itemcount - 1) = cell.Value
Next cell


'/// Change the output file name here! ///
sPDFName = "SCRAServicemembersCivilReliefAct.pdf"

'' stub here
sPDFPath = "\\csafsusers1\users\dyerm\Desktop\Brown - 1010557007\Documents\Black Knight\"

'Activate error handling and turn off screen updates
On Error GoTo EarlyExit
' Application.ScreenUpdating = False
Set pdfjob = New PDFCreator.clsPDFCreator

'Check if PDFCreator is already running and attempt to kill the process if so
Do
bRestart = False
Set pdfjob = New PDFCreator.clsPDFCreator
If pdfjob.cStart("/NoProcessingAtStartup") = False Then
'PDF Creator is already running. Kill the existing process
Shell "taskkill /f /im PDFCreator.exe", vbHide
DoEvents
Set pdfjob = Nothing
bRestart = True
End If
Loop Until bRestart = False

'Assign settings for PDF job
With pdfjob
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
DefaultPrinter = .cDefaultPrinter
.cDefaultPrinter = "PDFCreator"
.cClearCache
End With

'Delete the PDF if it already exists
If Dir(sPDFPath & sPDFName) = sPDFName Then Kill (sPDFPath & sPDFName)

'Print the document to PDF
With pdfjob
' change this filename each loop

'*****This is where the thing is happening****
For i = 0 To UBound(sFilenames)
.cPrintFile (sFilenames(i))
'Application.Wait Now + TimeValue("0:0:2")
Next i

'Wait until all the print jobs have entered the queue
Do Until pdfjob.cCountOfPrintjobs = UBound(sFilenames) + 1
DoEvents
Loop
.cCombineAll
.cPrinterStop = False

End With
'Wait until the PDF file shows up then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop

'Wait a bit longer for PDF Creator to finish
Application.Wait Now + TimeValue("0:0:2")

'reset original Windows' default printer
pdfjob.cDefaultPrinter = DefaultPrinter
pdfjob.cClose

Cleanup:
'Release objects and terminate PDFCreator
Set pdfjob = Nothing
Shell "taskkill /f /im PDFCreator.exe", vbHide
On Error GoTo 0
'Application.ScreenUpdating = True
Exit Sub

EarlyExit:
'Inform user of error, and go to cleanup section
MsgBox "There was an error encountered. PDFCreator has" & vbCrLf & _
"has been terminated on file " & sPDFName & " in bind. Please try again.", _
vbCritical + vbOKOnly, "Error"
Resume Cleanup

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default close adobe reader window

Matthew,
I believe PDFCreator has a SDK for doing this. You need to consult its
user guide to see how to automate it 'behind-the-scenes' and only
display the finished file for review.

IIRC, you'll need to get the window handle of the 1st running instance
of PDFCreator and set an object ref to it; -use that instance
throughout. (I can help with the required code)

Once you've got all your files consolidated into one, display (and
release) the PDFCreator instance so you can review the job. Then you
can close PDFCreator in the normal fashion

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default close adobe reader window

Sorry.., I was thinking of another app I used some years back with a
similar name!

I downloaded the free version so I could view its user guide. This
looks like an interesting supplement to Excel's built-in
"ExportToFixedFormat" feature for peaople who don't have anything like
Adobe Acrobat. (Their PDF Architect app look promising!)

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I get rid of Adobe Reader icon? ajnmxx Excel Discussion (Misc queries) 1 January 15th 10 03:33 PM
Opening a .pdf file with Adobe Reader 8.0 Otto Moehrbach Excel Programming 3 June 27th 07 03:44 AM
Opening a pdf file with Adobe Reader Otto Moehrbach Excel Programming 9 March 14th 07 05:54 PM
how i can take file from adobe reader and make it read with micr. ahmed nasr Excel Discussion (Misc queries) 0 May 25th 06 05:44 AM
Identifying version of Adobe Reader Andrew Excel Programming 5 September 14th 05 06:25 AM


All times are GMT +1. The time now is 02:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"