Consulting

Results 1 to 5 of 5

Thread: Excel 2007: Trying to change images' rotation after loading without selecting first

  1. #1

    Excel 2007: Trying to change images' rotation after loading without selecting first

    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

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Quote Originally Posted by Spielberg View Post
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    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

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    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/off...cel.oleobjects
    Last edited by Paul_Hossler; 05-30-2020 at 07:18 AM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    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!*

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •