Results 1 to 5 of 5

Thread: [RESOLVED] How to select the picture/image object in Excel worksheet

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    44

    Resolved [RESOLVED] How to select the picture/image object in Excel worksheet

    Hi, I have this excel worksheet with multiple pictures.
    I need to find a way to select each pictures programmatically and do things to it (resizing, move, etc.).
    How can I select the picture programmatically without knowing the picture/image name/ID?

    PS: the pictures are already in the worksheet, not inserted by my macro.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to select the picture/image object in Excel worksheet

    Record a macro of you doing your actions and then stop and chheck out the generated module code.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    44

    Re: How to select the picture/image object in Excel worksheet

    Quote Originally Posted by RobDog888
    Record a macro of you doing your actions and then stop and chheck out the generated module code.
    I've done that before posting the question, hence the question.
    It selects the picture by referring it to the name
    Code:
    ActiveSheet.Shapes("_ctl0_reportlist__ctl0_Image3").Select
    ...
    ...
    ActiveSheet.Shapes("_ctl0_reportlist__ctl1_Image3").Select
    ...
    ...
    ActiveSheet.Shapes("_ctl0_reportlist__ctl2_Image3").Select
    ...
    ...
    I can see the ctl0 -> ctl1 -> ctl2 incremented, but the rest doesn't necessarily always like that (depending on what generated the excel file in the first place) - so I can't select the image without first knowing the name.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to select the picture/image object in Excel worksheet

    You can iterate through the Shapes collection using a For Each loop.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    44

    Re: How to select the picture/image object in Excel worksheet

    Quote Originally Posted by RobDog888
    You can iterate through the Shapes collection using a For Each loop.
    Thanks!!! I didn't remember to use For Each loop, as I hardly use it.

Posting Permissions

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



Click Here to Expand Forum to Full Width