'Excel VBA Copy Rotate and Paste at Multiple Cells - Only one is rotating not others
I am using an excel VBA function to generate a barcode, make is as image and paste it with rotation at two different cells. However, only the first paste is getting rotated and not the second one. Can someone help please?
Please find below my code:
Set xObjOLE = ActiveSheet.OLEObjects.Add("BARCODE.BarCodeCtrl.1")
xObjOLE.Object.Style = 7
xObjOLE.Object.Value = "0123456789"
xObjOLE.Width = 120
xObjOLE.Height = 30
xObjOLE.CopyPicture xlScreen, xlPicture
Set xRRg = Application.Range("H5")
ActiveSheet.Paste xRRg
With Selection
.ShapeRange.Rotation = 270
End With
Set xRRg = Application.Range("S5")
ActiveSheet.Paste xRRg
With Selection
.ShapeRange.Rotation = 270
End With
xObjOLE.Delete
Solution 1:[1]
my first suggestion is rotating the original image, then paste it in two places.
The alternative is selecting the copies, but for that I need to know if you have other images in the file.
First solution
To make it reproducible I am adding only the code for the "Set" chunk. Given that, you need to select an image first, then run my code.
Sub MacroCopy()
'Rotate first
Selection.ShapeRange.Rotation = 270
Selection.CopyPicture xlScreen, xlPicture
Set xRRg = Application.Range("H5")
ActiveSheet.Paste xRRg
Set xRRg = Application.Range("S5")
ActiveSheet.Paste xRRg
'If you need to rotate back to zero
Selection.ShapeRange.Rotation = 0
End Sub
Please let me know if you have any question.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Fernando Barbosa |
