Results 1 to 4 of 4

Runtime Error -2147417848 (80010108) The Object Invoked Has Disconnected

Threaded View

  1. #1
    Registered User
    Join Date
    03-27-2013
    Location
    Gastonia, NC
    MS-Off Ver
    Excel 2010
    Posts
    2

    Smile Runtime Error -2147417848 (80010108) The Object Invoked Has Disconnected

    I've been a longtime lurker and am now a first time poster! I hope this isn't the case, but it looks like it may be a bug on Microsoft's side of things.

    I have a relatively simple macro that is run on the BeforeClose and BeforePrint conditions. The sub's purpose is to print a pdf to a networked location with a time stamp.

    Everything works great as long as the macro is not called in the BeforePrint event. Here is the code:

    Private Sub exportPDF()
    'Application.ScreenUpdating = False
    
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim filePath As String
    Dim pdfName As String
    Dim fullPDF As String
    Dim TimeStamp As String
    
    Set wb = ThisWorkbook
    Set ws = wb.Sheets(1)
    TimeStamp = Format(Now(), "mm-dd-yyyy_hhmm-AMPM")
    
    'On Error GoTo ErrHandler:
    filePath = Left(wb.FullName, InStrRev(ActiveWorkbook.FullName, Application.PathSeparator))
    pdfName = Replace(ActiveWorkbook.Name, ".xls", "_")
    fullPDF = filePath + pdfName + TimeStamp
    
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
           Filename:=fullPDF, _
           Quality:=xlQualityMinimum, IncludeDocProperties:=True, _
           IgnorePrintAreas:=False, OpenAfterPublish:=False
    
    'ErrHandler:
    'Debug.Print Err.Number & "-" & Err.Description
    Exit Sub
    
    'Application.ScreenUpdating = True
    End Sub
    Now, this instance works fine...
    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    
    If Not Me.Saved Then Me.Save
    
    End Sub
    But if I put the call to exportPDF in there, it throws up an error or crashes depending on if I have the error handler on.

    Edit: This code seems to "activate" even when the sub of BeforePrint shouldn't even be invoked. It crashes even when I simply try to close the file. The exact same code is invoked at the BeforeClose sub, and it causes no problems there.

    Moderator's note: Moved to other forum to get better exposure for this specific problem --6SJ

    Ok, I fixed the issue. The desired end result was a time stamped PDF in the same directory as the Excel file. I also wanted this file saved every time the worksheet was closed and/or printed. This was achieved by the Me.Save call in the BeforeClose and BeforePrint subs. I was trying to also call the exportPDF sub I previously defined in the BeforeClose and BeforePrint subs. This is where the error was invoked. The solution was to call the exportPDF sub in the AfterSave sub.


    This is my fully functional code:
    Private Sub exportPDF()
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim filePath As String
    Dim pdfName As String
    Dim fullPDF As String
    Dim TimeStamp As String
    
    Set wb = ThisWorkbook
    Set ws = wb.Sheets(1)
    TimeStamp = Format(Now(), "mm-dd-yyyy_hhmm-AMPM")
    
    filePath = Left(wb.FullName, InStrRev(ActiveWorkbook.FullName, Application.PathSeparator))
    pdfName = Replace(ActiveWorkbook.Name, ".xls", "_")
    fullPDF = filePath + pdfName + TimeStamp
    
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
           Filename:=fullPDF, _
           Quality:=xlQualityMinimum, IncludeDocProperties:=True, _
           IgnorePrintAreas:=False, OpenAfterPublish:=False
    Application.ScreenUpdating = True
    Application.DisplayAlerts = False
    End Sub
    
    Private Sub Workbook_AfterSave(ByVal Success As Boolean)
    exportPDF
    
    End Sub
    
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    
    If Not Me.Saved Then Me.Save
    
    End Sub
    
    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    
    If Not Me.Saved Then Me.Save
    
    End Sub
    Thank you to everyone that looked at this. I hope this helps someone else in the future.
    Last edited by johndoe86x; 10-29-2013 at 10:03 AM. Reason: Solved

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. System Error &H80010108 (-2147417848) object invoked disconnected client
    By xclrInTraining in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-30-2013, 10:14 AM
  2. Replies: 7
    Last Post: 05-15-2013, 09:02 AM
  3. 2147417848 automation error the object invoked has disconnected from its clients
    By KasiaFavourite in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-12-2011, 10:44 AM
  4. -2147417848 automation error the object invoked has disconnected from its clients
    By ajaykgarg in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-12-2011, 08:10 AM
  5. Replies: 12
    Last Post: 04-15-2010, 08:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1