Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Run-time error: The object invoked has disconnected from its clients

I am running the VBA code below in Excel 2002 SP3 under Windows XP
SP3. I received this error:

Run-time error '-2147417848(80010108)'
Automation error
The object invoked has disconnected from its clients

at this line of code:

MsgBox "The document " & FileName(WordDoc.name) & " has printed",
vbInformation, "PDF Print Status"

I Googled this error and found a few threads, but none of the seem to
relate to the problem I am having.

Anbody have any ideas what is going on?

The code, which resides in Excel, is trying to use the PDFCreator
application to print a Word file to PDF. To run it, you have to have
PDFCreator installed and have the Reference to PDFCreator checked in
the VBE.

Thanks, Alan

Option Explicit

Sub TESTPrintWordToPDF()
Debug.Print "Starting print of test.doc"
PrintWordToPDFCreator "C:\Documents and Settings
\thomasja.DLVASTRIKE\Desktop\PPT Compat\Excel\test.doc"
Debug.Print "Starting print of References.doc"
PrintWordToPDFCreator "C:\Documents and Settings
\thomasja.DLVASTRIKE\Desktop\PPT Compat\Excel\References.doc"
Debug.Print "Starting print of Issues.doc"
PrintWordToPDFCreator "C:\Documents and Settings
\thomasja.DLVASTRIKE\Desktop\PPT Compat\Excel\Issues.doc"
End Sub

Sub PrintWordToPDFCreator(WordDocPath As String)
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String, sPDFPath As String
Dim pos As Integer, sWordName As String
Dim sPrinter As String
Dim bRestart As Boolean
Dim bBkgrndPrnt As Boolean
Dim WordApp As Word.Application
Dim WordDoc As Word.Document

Debug.Print "setting file/path name"
' Set file and path name
sWordName = FileName(WordDocPath)
pos = InStr(1, sWordName, ".doc")
If (pos = 0) Then
DisplayErrorMessage (sWordName & " is not a Word document")
Exit Sub
Else
sPDFName = Replace(sWordName, ".doc", ".pdf")
sPDFPath = FolderName(WordDocPath)
End If

Debug.Print "checking file existence"
If Not CheckFileExist(WordDocPath) Then
MsgBox "The file " & WordDocPath & " does not exist"
Exit Sub
End If

Debug.Print "setting Word objects"
Set WordApp = New Word.Application
Set WordDoc = WordApp.Documents.Open(WordDocPath)

'Activate error handling, capture properties and set req'd
settings
'On Error GoTo EarlyExit
Debug.Print "setting printer props"
With WordApp
sPrinter = CStr(.ActivePrinter)
.ActivePrinter = "PDFCreator"
bBkgrndPrnt = .Options.PrintBackground
.Options.PrintBackground = False
.ScreenUpdating = False
End With

'Check if PDFCreator is already running and attempt to kill the
process if so
Debug.Print "Check if PDFCreator is already running"
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

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

Debug.Print "Printing Word doc to PDF"
'Print document to PDF
WordDoc.PrintOut copies:=1

Debug.Print "Checking printer queue"
'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop

Debug.Print "Setting cPrinterStop = False"
'pdfjob.cPrinterStop = False

'Wait until the file shows up before closing PDF Creator
Debug.Print "Waiting until PDF file is created"
Do
DoEvents
Loop Until Dir(sPDFPath & sPDFName) = sPDFName
' Close Word document
Debug.Print "Closing Word document"
WordDoc.Close SaveChanges:=False

Cleanup:
'On Error Resume Next
Debug.Print "Cleaning up . . . "
'Release objects and terminate PDFCreator
MsgBox "The document " & FileName(WordDoc.name) & " has printed",
vbInformation, "PDF Print Status"
DoEvents
pdfjob.cClose
Shell "taskkill /f /im PDFCreator.exe", vbHide
Set pdfjob = Nothing
'Reset all application settings to user's original settings
With WordApp
.ScreenUpdating = True
.ActivePrinter = sPrinter
.Options.PrintBackground = bBkgrndPrnt
End With
' WordApp.Quit
Set WordApp = Nothing
Set WordDoc = Nothing
Debug.Print "All done"
Exit Sub

EarlyExit:
'On Error Resume Next
Debug.Print "Exiting early . . . "
'Inform user of error, and go to cleanup section
MsgBox "There was an error encountered. PDFCreator has" & vbCrLf
& _
"has been terminated. Please try again.", _
vbCritical + vbOKOnly, "Error"
' Resume Cleanup
Set WordDoc = Nothing
Debug.Print "I have exited early"
End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Run-time error: The object invoked has disconnected from its clients

Hi

Be sure to set the the reference to PDFCreator.

In the VBA editor goto Tools References Check PDFCreator OK

Hopes this helps

---
Per


"Alan" skrev i meddelelsen
...
I am running the VBA code below in Excel 2002 SP3 under Windows XP
SP3. I received this error:

Run-time error '-2147417848(80010108)'
Automation error
The object invoked has disconnected from its clients

at this line of code:

MsgBox "The document " & FileName(WordDoc.name) & " has printed",
vbInformation, "PDF Print Status"

I Googled this error and found a few threads, but none of the seem to
relate to the problem I am having.

Anbody have any ideas what is going on?

The code, which resides in Excel, is trying to use the PDFCreator
application to print a Word file to PDF. To run it, you have to have
PDFCreator installed and have the Reference to PDFCreator checked in
the VBE.

Thanks, Alan

Option Explicit

Sub TESTPrintWordToPDF()
Debug.Print "Starting print of test.doc"
PrintWordToPDFCreator "C:\Documents and Settings
\thomasja.DLVASTRIKE\Desktop\PPT Compat\Excel\test.doc"
Debug.Print "Starting print of References.doc"
PrintWordToPDFCreator "C:\Documents and Settings
\thomasja.DLVASTRIKE\Desktop\PPT Compat\Excel\References.doc"
Debug.Print "Starting print of Issues.doc"
PrintWordToPDFCreator "C:\Documents and Settings
\thomasja.DLVASTRIKE\Desktop\PPT Compat\Excel\Issues.doc"
End Sub

Sub PrintWordToPDFCreator(WordDocPath As String)
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String, sPDFPath As String
Dim pos As Integer, sWordName As String
Dim sPrinter As String
Dim bRestart As Boolean
Dim bBkgrndPrnt As Boolean
Dim WordApp As Word.Application
Dim WordDoc As Word.Document

Debug.Print "setting file/path name"
' Set file and path name
sWordName = FileName(WordDocPath)
pos = InStr(1, sWordName, ".doc")
If (pos = 0) Then
DisplayErrorMessage (sWordName & " is not a Word document")
Exit Sub
Else
sPDFName = Replace(sWordName, ".doc", ".pdf")
sPDFPath = FolderName(WordDocPath)
End If

Debug.Print "checking file existence"
If Not CheckFileExist(WordDocPath) Then
MsgBox "The file " & WordDocPath & " does not exist"
Exit Sub
End If

Debug.Print "setting Word objects"
Set WordApp = New Word.Application
Set WordDoc = WordApp.Documents.Open(WordDocPath)

'Activate error handling, capture properties and set req'd
settings
'On Error GoTo EarlyExit
Debug.Print "setting printer props"
With WordApp
sPrinter = CStr(.ActivePrinter)
.ActivePrinter = "PDFCreator"
bBkgrndPrnt = .Options.PrintBackground
.Options.PrintBackground = False
.ScreenUpdating = False
End With

'Check if PDFCreator is already running and attempt to kill the
process if so
Debug.Print "Check if PDFCreator is already running"
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

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

Debug.Print "Printing Word doc to PDF"
'Print document to PDF
WordDoc.PrintOut copies:=1

Debug.Print "Checking printer queue"
'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop

Debug.Print "Setting cPrinterStop = False"
'pdfjob.cPrinterStop = False

'Wait until the file shows up before closing PDF Creator
Debug.Print "Waiting until PDF file is created"
Do
DoEvents
Loop Until Dir(sPDFPath & sPDFName) = sPDFName
' Close Word document
Debug.Print "Closing Word document"
WordDoc.Close SaveChanges:=False

Cleanup:
'On Error Resume Next
Debug.Print "Cleaning up . . . "
'Release objects and terminate PDFCreator
MsgBox "The document " & FileName(WordDoc.name) & " has printed",
vbInformation, "PDF Print Status"
DoEvents
pdfjob.cClose
Shell "taskkill /f /im PDFCreator.exe", vbHide
Set pdfjob = Nothing
'Reset all application settings to user's original settings
With WordApp
.ScreenUpdating = True
.ActivePrinter = sPrinter
.Options.PrintBackground = bBkgrndPrnt
End With
' WordApp.Quit
Set WordApp = Nothing
Set WordDoc = Nothing
Debug.Print "All done"
Exit Sub

EarlyExit:
'On Error Resume Next
Debug.Print "Exiting early . . . "
'Inform user of error, and go to cleanup section
MsgBox "There was an error encountered. PDFCreator has" & vbCrLf
& _
"has been terminated. Please try again.", _
vbCritical + vbOKOnly, "Error"
' Resume Cleanup
Set WordDoc = Nothing
Debug.Print "I have exited early"
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Run-time error: The object invoked has disconnected from itsclients

Thanks for the suggestion, but I already did this. It will not
compile without me doing that.
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
object invoked is disconnected from its clients Ken Excel Programming 4 June 27th 07 07:55 PM
Automation Error : The Object Invoked Has Disconnected From Its Clients !! [email protected] Excel Programming 3 June 17th 05 01:17 PM
Automation Error: The Object Invoked Has Disconnected from Its Clients (Excel) Vaibhav Excel Programming 0 September 8th 03 04:57 PM
Automation Error: The Object Invoked Has Disconnected from Its Clients Vaibhav Dandavate Excel Programming 0 September 8th 03 04:05 PM


All times are GMT +1. The time now is 08:24 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"