Bizarre behavior on Excel 2011 (for Mac)

mcomp72

Active Member
Joined
Aug 14, 2016
Messages
305
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have discovered a bizarre problem with Excel 2011 (for Mac) and cannot for the life of me figure out how to solve it.

I've developed a workbook that needs to work on both Windows & Mac. I've tested some code on Windows, and it works fine. I've tested it on Excel 2019 for Mac and it works fine. However, on Excel 2011 it causes an error. What's bizarre is that if I put in a breakpoint, and then after the code hits the breakpoint, I press F5 (Continue), it works with no error.

Here's the code:
VBA Code:
'This will copy all images, except "LeftArrow" and "RightArrow"
For Each S In sourceWS.Shapes

    If S.Name <> "LeftArrow" And S.Name <> "RightArrow" Then
   
        If S.Visible = True And S.Type = msoPicture Then
   
            OriginalName = S.Name
            S.Name = "FixedName"
            S.Copy
            targetWS.Paste
            targetWS.Shapes("FixedName").Top = S.Top
            targetWS.Shapes("FixedName").Left = S.Left
            S.Name = OriginalName
            targetWS.Shapes("FixedName").Name = OriginalName
       
        End If
       
    End If
   
Next S

The line that is causing the error on Excel 2011 is

VBA Code:
targetWS.Paste

The error is Run-time 1004: Method 'Paste' of object '_Worksheet' failed.

What's even more bizarre is I have similar code in another sub, and that sub doesn't cause any error on Excel 2011.

Does anyone have any ideas what might be wrong?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Is targetWS the ActiveSheet when the code is run?
 
Upvote 0
Yep. When the error happened, I took a look at that, and targetWS was the ActiveSheet. Good idea, though. I thought that might have been it, as well.

I even tried setting the ActiveSheet to the sourceWS before the Copy line, and then switched the ActiveSheet to the targetWS before the Paste line. No luck there.
 
Upvote 0
Any sheet protection? have you tried specifying a cell to paste to in the code? Any merged cells?
 
Upvote 0
Any sheet protection? have you tried specifying a cell to paste to in the code? Any merged cells?
I have confirmed that neither sheet is protected. I have also confirmed that both sheets are "xlSheetVisible".

I tried recording a macro of me copying the image myself, and then I used that code. I replaced this code:

VBA Code:
S.Copy
targetWS.Paste

with this:

VBA Code:
sourceWS.Activate
ActiveSheet.Shapes.Range(Array("FixedName")).Select
Selection.Copy
targetWS.Activate 'I tried it both with and without this line
targetWS.Select
targetWS.Range("E4").Select
ActiveSheet.Paste

Still getting the same error, this time on the ActiveSheet.Paste line.

There ARE merged cells on both the sourceWS and targetWS. I wasn't aware that that could make a difference. I don't think I can do anything about the merged cells, unfortunately. The sourceWS has been designed by someone else, and the code I've written is designed to copy everything from it to a new sheet in the same workbook. Copying the cells doesn't cause any error; only the pictures.
 
Upvote 0

Forum statistics

Threads
1,223,157
Messages
6,170,419
Members
452,325
Latest member
BlahQz

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