PDA

View Full Version : [SOLVED:] Excel 2007: Trying to change images' rotation after loading without selecting first



Spielberg
05-29-2020, 12:24 PM
Here's my second post, after amazing replies from some great folks! Thank you all for that.

So, when I insert an image - my img variable preset with the path and filename:



With ActiveSheet.Pictures.Insert(img)
.Top = ActiveSheet.Cells(FY, FX).Top
.Left = ActiveSheet.Cells(FY, FX).Left
End With


I am able to adjust the position of it with no problem (.Top and .Left).

.Rotation and IncrementRotation do not work within the With/End With statements.

Without having to use .Select, is there a way to rotate it?

Thank you in advance to all the great gurus out there!

Mike

Paul_Hossler
05-29-2020, 07:08 PM
Here's my second post, after amazing replies from some great folks! Thank you all for that.

So, when I insert an image - my img variable preset with the path and filename:

.Rotation and IncrementRotation do not work within the With/End With statements.

Without having to use .Select, is there a way to rotate it?

Mike


.Rotation and IncrementRotation do work, but .ShapeRange is their parent




Option Explicit


Sub test1()
Dim img As String
Dim FY As Long, FX As Long

img = "C:\Users\Daddy\Work\Dilbert Characters\Dilbert JPGs (100x100)\Dogbert.jpg"

FX = 10
FY = 10

With ActiveSheet.Pictures.Insert(img)
.Top = ActiveSheet.Cells(FY, FX).Top
.Left = ActiveSheet.Cells(FY, FX).Left
.ShapeRange.Rotation = 45
End With


End Sub



The easy way to figure out a lot of the object model is to record just a small macro doing manually where I'm stuck and want the macro to do

The recorder is VERY literal and records everything (hard coded cell addresses, Selects, Small Scrolls, ....) so I don't use it's code, but it does point me in the direction

Like below, the .Select and Selection. told me about ShapeRange



Sub Macro3()
'
' Macro3 Macro
'


'
ActiveSheet.Pictures.Insert("C:\Users\Daddy\Work\Dilbert Characters\Dilbert JPGs (100x100)\Dilbert.jpg").Select
Selection.ShapeRange.IncrementLeft 204
Selection.ShapeRange.IncrementTop -87
Selection.ShapeRange.Rotation = 45
End Sub

Spielberg
05-29-2020, 07:31 PM
You sir, are a genius, thank you. I really do try to figure things out myself first. I try everything I can to get it to work, really. But sometimes it just doesn't work to the point I have to look elsewhere for help, googling, etc. Then I found this forum today. Other forums have "recent" posts dating back 8+ years.

The problem is with Excel 2007, even with SP3, there is SO much that is doesn't record. I know this is old, but I have SO much written in 2007, I am dreading the day I have to upgrade and then spend the rest of my life tweaking or changing things!

So many commands, and one I wish would work; .BringToFront, is in the help file, but hasn't been implemented. so when i need to move an object that is behind something, I cut it then immediately paste it. I tried everything - even using SendKeys as a workaround. I even tried making a function out of it, but functions are kinda funny sometimes. Sometimes they work, sometimes they don't. Odd... Sorry I got off topic there...

Thank you again sir. You rock.

Mike

Paul_Hossler
05-30-2020, 07:03 AM
Try this to put a shape on top of the pile





ActiveSheet.Shapes(1).Zorder msoBringToFront




.BringToFront works with OLE objects:




OLEObject represents an activex control or a linked or embedded ole object on a worksheet.

This page provides code for the methods of the Excel class OLEObject: Add, Copy, Duplicate, Delete, Activate, Select, BringToFront, CopyPicture, Cut, SendToBack, Update, Verb, Item.



https://docs.microsoft.com/en-us/office/vba/api/excel.oleobjects

Spielberg
05-30-2020, 01:55 PM
I scrolled a little too quickly and missed the msoBringToFront, and also replied on the wrong thread - had them both open at the same time.

As I've said before, sir, YOU ARE A GENIUS! it worked perfectly and *THANK YOU!*