Macro stops working after saving workbook

jmpatrick

Active Member
Joined
Aug 17, 2016
Messages
477
Office Version
  1. 365
Platform
  1. Windows
Hello, all.

I have this fabulous macro that (when a link is clicked) combines data and copies the results suitable for pasting outside of Excel. This works great UNTIL I hit save. Once I do it no longer produces pasteable text unless I close and reopen the Workbook. It works fine as long as I don't save the file.

VBA Code:
Sub ShippingInstructions()

    Application.EnableEvents = False
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
 
    Sheets("ShippingInstructions").Visible = True
    
    Sheets("ShippingInstructions").Range("A1") = Cells(ActiveCell.Row, "B")
    Sheets("ShippingInstructions").Range("E1") = Cells(ActiveCell.Row, "E")
    Sheets("ShippingInstructions").Select
    Range("G1").Select

    Dim objData As New DataObject
    Dim strTemp As String
    strTemp = Replace(ActiveCell.Value, Chr(10), vbCrLf)
    objData.SetText (strTemp)
    objData.PutInClipboard
 
    Sheets("Calendar").Select
 
    Sheets("ShippingInstructions").Visible = False
 
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
 
End Sub
 
Last edited:
Can you elaborate on how you're verifying things don't work?
I ask because setting up a test workbook from your descriptions and picture
the code from post 1 allows me to paste from the clipboard into NotePad at any time before save or after save or while closed or after re-opening.

OK, that's crazy. It's working fine for me today as well. We'll see how things look Monday morning. Thanks for your help.
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I'm sorry to report that this is still broken. I tried the suggestion above and it didn't work, meaning I can't paste the contents of G1 before or after a save.

Here's what I've learned:

1. The macro works fine as long as the user DOES NOT click Save.

2. After the user clicks Save the first part of the macro still works, meaning I can see the text going to the Clipboard by monitoring Clipboard in Excel, but the text can't be pasted anywhere (inside or outside of Excel).

clipboard1.png
 
Upvote 0
I THINK I figured this out!

Going to do some more testing and report back.
 
Upvote 0
Sadly, I must again report that this is NOT fixed. Can't figure out why I cannot paste Excel data outside of Excel AFTER I click save.
 
Upvote 0
I still don't know how you are verifying this.
If you open, let's say NotePad, and bring up the viewer for the clipboard your code writes to, the Windows clipboard, are you saying that double clicking the last (or any) thing written to that clipboard from within Excel doesn't get pasted to NotePad ?
 
Upvote 0
I still don't know how you are verifying this.
If you open, let's say NotePad, and bring up the viewer for the clipboard your code writes to, the Windows clipboard, are you saying that double clicking the last (or any) thing written to that clipboard from within Excel doesn't get pasted to NotePad ?

Hope this helps...

paste1.png

paste2.png

paste3.png

paste4.png
paste5.png

paste6.png
paste7.png

paste8.png
 
Upvote 0
And what if you do that from the clipboard your code is writing to rather than the Excel clipboard ?

Windows Start > Settings > Clipboard >

Clipboard.png
 
Upvote 0
Sorry, all I can do is wish you luck and move on as I can not replicate the issue you describe.
 
Upvote 0
Sorry, all I can do is wish you luck and move on as I can not replicate the issue you describe.

Thanks for trying. There's so many variables at play here. Maybe a program other than Excel is breaking it. Who knows.
 
Upvote 0

Forum statistics

Threads
1,214,996
Messages
6,122,636
Members
449,092
Latest member
bsb1122

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