Run-time error -2147417848 (80010108) automation error: the object invoked has disconnected from its clients

Cashu

New Member
Joined
Jan 5, 2024
Messages
7
Office Version
  1. 2021
Platform
  1. Windows
Good morning guys,

Code:
Set mybook = Workbooks.Open("C:\Normal Files\Engineer Spreadsheet.xlsx")
Workbooks("Engineer Spreadsheet.xlsx").Activate
If ActiveSheet.Name = Format(Date - 2, "dd-mmm-yyyy") Then
ThisWorkbook.Sheets("ABC").Copy after:=mybook.Sheets(Format(Date - 2, "DD-MMM-YYYY"))
Else
ThisWorkbook.Worksheets("ABC").Copy after:=mybook.Worksheets(Format(Date - 1, "DD-MMM-YYYY"))
End If
ActiveSheet.Name = Format(Date, "DD-MMM-YYYY")

This automation error occurs at line ThisWorkbook.Worksheets("ABC").Copy after:=mybook.Worksheets(Format(Date - 1, "DD-MMM-YYYY"))
I have tried several ways it works fine but sometimes it throws error at this line.Any help is much appreciated.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Just a guess... there's only 2 digits in months, so date format is DD-MM-YYYY not DD-MMM-YYYY. HTH. Dave
ps Welcome to the Board! Please use code tags when pasting code.
 
Upvote 0
Hi MdNovice Hlp The example of this format is 08-JAN-2024.Thank you for this warm welcome.Sure will start using code tags.
 
Upvote 0
Hi again *Cashu. Thanks for the learning and my apologies for the the uninformed "help". This probably doesn't matter, but the one line of code uses mybook.worksheets and the other mybook.sheets? I'm guessing again, but it seems likely that occasionally the sheet doesn't exist (maybe a 3 day wkend?). If all else fails, you could trial setting the sheet name before the copy/paste...
Code:
Dim DateStr As String
If ActiveSheet.Name = Format(Date - 2, "dd-mmm-yyyy") Then
DateStr = Format(Date - 2, "DD-MMM-YYYY")
ThisWorkbook.Sheets("ABC").Copy after:=mybook.Sheets(DateStr)
Else
DateStr = Format(Date - 1, "DD-MMM-YYYY")
ThisWorkbook.Worksheets("ABC").Copy after:=mybook.Worksheets(DateStr)
End If
ActiveSheet.Name = Format(Date, "DD-MMM-YYYY")
HTH. Dave
 
Upvote 0
Solution
Thank you for the suggestion.It was of great help.

NdNoviceHlp buddy.I have changed the code and it has started working.

 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

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