Pasting selection into sheet in another workbook fails if excel is opened in another instance

tomleitch

Board Regular
Joined
Jan 3, 2012
Messages
189
I have a spreadsheet that imports data from a different workbook to import and update items in the destination book by pasting data from the second workbook...

It all works absolutely fine - although in some cases when the second workbook (with the data to import) is opened, it opens in a new instance of excel rather than a window of the same version.

This means that when you copy the data to the clipboard it is handled in a different way and the macro crashes.

This microsoft article mentions the issue:

https://docs.microsoft.com/en-us/office/troubleshoot/excel/cannot-paste-attributes

The second spreadsheet is normally opened straight from an email - so is there any way to stop excel opening this second instance? or to modify my macro code to handle this?

An excerpt of the code that I am using is:

Code:
If Application.ClipboardFormats(1) = -1 ThenMsgBox "Nothing to paste!"
Exit Sub


End If
 


ThisWorkbook.Sheets.Add
ActiveSheet.Name = "UPDATE TOOL2"
ActiveSheet.Columns("G").ColumnWidth = 18
ThisWorkbook.Sheets.Add
ActiveSheet.Name = "UPDATE TOOL"
ActiveSheet.Columns("G").ColumnWidth = 18


Sheets("OPS PLANNER").Activate


Application.ScreenUpdating = True




'On Error GoTo 90


Sheets("UPDATE TOOL").Activate


    Set ws1 = Sheets("OPS PLANNER")
    Set ws2 = Sheets("UPDATE TOOL2")
    Set Ws3 = Sheets("ARCHIVED")
   


ThisWorkbook.Sheets("UPDATE TOOL").Range("A1").PasteSpecial






Box2 = MsgBox("Do you wish to import displayed data?", vbOKCancel, "DATA IMPORT")






If Box2 = vbOK Then

I have tried using normal paste rather than paste special but it still fails.


Any suggestions?


Thanks
Tom
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Managed to fix the issue by using the PasteValues when pasting

Line changed to

Code:
ThisWorkbook.Sheets("UPDATE TOOL").Range("A1").PasteSpecial Paste:=xlPasteValues

And now it works and has stopped it from crashing.
 
Upvote 0

Forum statistics

Threads
1,224,737
Messages
6,180,668
Members
452,992
Latest member
TokugawaIesuma

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