"-2147417848 Automation error The object invoked has disconnected from its clients" - When Copying Worksheets from One Workbook to Another.

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi, 'm recieving this error message "-2147417848 Automation error The object invoked has disconnected from its clients" - When Copying Worksheets from One Workbook to Another.
And sometime it happen that workbook fails to open up...
Code:
[FONT=Courier New]Set MnWb= Workbooks.Open(Filename:=myMainWbstr, ReadOnly:=True, UpdateLinks:=False, CorruptLoad:=True)[/FONT]

Error happens in the line below...
Sometime when i manually F8 one line after another it goes through...
Code:
[FONT=Courier New]Set [FONT=Courier New]XWb[/FONT]= Workbooks.Open(Filename:=[FONT=Courier New]XWbFile[/FONT], ReadOnly:=True)
                        For Each sh In [FONT=Courier New]XWb[/FONT].Worksheets
                            If sh.Name <> "Notes" And sh.Visible = xlSheetVisible Then
                                [U]Workbooks(XWb.Name).Sheets(sh.Name).Copy After:=Workbooks(MnWb.Name).Sheets(Workbooks([FONT=Courier New]MnWb[/FONT].Name).Sheets.Count)
[/U]                                Sheet4.Cells(i, 36).Value = Sheet4.Cells(i, 36).Value + 1
                            End If
                        Next sh[/FONT]
 
Last edited by a moderator:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try this,

Code:
       Set XWb = Workbooks.Open(Filename:=XWbFile, ReadOnly:=True)
                    
                        For Each sh In XWb.Worksheets
                            If sh.Name <> "Notes" And sh.Visible = xlSheetVisible Then
                                sh.Copy MnWb.Sheets(1)
                                Sheet4.Cells(i, 36).Value = Sheet4.Cells(i, 36).Value + 1
                            End If
                        Next sh
 
Upvote 0
Thanks for quick answer but the problem is at the workbooks.open method. I have tried different ways but there seems to be something which I don't understand...When I place/hover I cursor over xwb it shows "nothing" which is why it is failing to copy the sheet...What could be the reason? I have tried searching in web but of no much help...pls help...
 
Upvote 0
I know you may have tried this and it does not do anything different to your original code but try this and see if the file name is correct in the Intermediate window.


Code:
myMainWbstr = "YourFilePathHere"Workbooks.Open Filename:=myMainWbstr, ReadOnly:=True, UpdateLinks:=False, CorruptLoad:=True
Set MnWb = ActiveWorkbook
Debug.Print MnWb.Name
 
Upvote 0
That above code was for some reason when I posted ,joined two lines together. It is supposed to look like this.

It did it again, what is up with the formatting of posts on this site.

Code:
myMainWbstr = "YourFilePathHere"    
Workbooks.Open Filename:=myMainWbstr, ReadOnly:=True, UpdateLinks:=False, CorruptLoad:=True
    Set MnWb = ActiveWorkbook
    Debug.Print MnWb.Name
 
Upvote 0
Hi ***anDave, when i debug the file name is reflecting correctly. I confirmed it by copying the link and manually running the link which opened the file.

thanks again.
 
Upvote 0
Hi, sorry coudnt respond earlier.
sometime xwb fails to open and gives and error at
sh.Copy MnWb.Sheets(1) 'Error is - Variable ..... not defined...

however when xwb opens it still gives and error at
sh.Copy MnWb.Sheets(1) 'Error is - Automation error2147.....

Code:
Set XWb = Workbooks.Open(Filename:=XWbFile, ReadOnly:=True)
                        For Each sh In XWb.Worksheets
                            If sh.Name <> "Notes" And sh.Visible = xlSheetVisible Then
                                sh.Copy MnWb.Sheets(1)
                                Sheet4.Cells(i, 36).Value = Sheet4.Cells(i, 36).Value + 1
                            End If
                        Next sh
 
Upvote 0
ok, i finally found the problem....XWbFile = Range("A1").value & Range("A2").value & Range("A3").value
now i made xwv = Range("A2").value and it worked perfect...

thanks for all the help...
 
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,785
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top