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:
The line that is causing the error on Excel 2011 is
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?
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?