+ Reply to Thread
Results 1 to 5 of 5

VBA to add picture to cell only works with landscape pictures

  1. #1
    Registered User
    Join Date
    02-18-2004
    MS-Off Ver
    2013 and 365
    Posts
    20

    VBA to add picture to cell only works with landscape pictures

    *Disclaimer I have posted this question on MyOnlineTrainingHub*

    Using the below code to add pictures to excel when you click in a cell, it works as expected with landscape images but portrait ones are added to the right and above the target cell.

    I have added the workbook and three pictures and a screen shot of where the macro places them

    Clicking in L3 Landscape correct orientation is placed in the correct cell

    Clicking in M3 Landscape Upside down is placed below and to the right

    Clicking in N3 Portrait is placed up and to the right.



    The Portrait one should be resized to fit in the cell vertically as well

    the only difference between the pictures is the angle the phone was held at to take the pictures but when selecting them the grab handles are in different positions.



    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    I have tried adding this extra check but it doesnt do anything

    Please Login or Register  to view this content.
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA to add picture to cell only works with landscape pictures

    The JPEG image format saves image orientation as metadata which Excel's Picture object seems to ignore. If you save the images as png or bmp, your image orientations are actual and you wouldn't have that issue. I don't have a solution to fix JPEG files. There's probably some clever way to read that meta data and fix the orientation, but it's beyond me.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: VBA to add picture to cell only works with landscape pictures

    You could probably adjust based on the rotation (I'd also suggest avoiding Pictures.Insert as it's deprecated):

    Please Login or Register  to view this content.
    Rory

  4. #4
    Registered User
    Join Date
    02-18-2004
    MS-Off Ver
    2013 and 365
    Posts
    20

    Re: VBA to add picture to cell only works with landscape pictures

    Thats great Rory and I didnt realise Pictures.Insert was deprecated

    John

  5. #5
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: VBA to add picture to cell only works with landscape pictures

    Glad we could help. Please remember to mark the thread solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Lookup for pictures by picture number
    By Ssaamirr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-14-2014, 04:16 AM
  2. Add pictures to sheet with picture name based on cell content
    By jprlimey in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-27-2014, 09:44 AM
  3. Place pictures in specified cells from picture file name and path in another cell
    By coreytroy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-22-2013, 04:59 AM
  4. Landscape Printing works on one Printer, but not another.
    By VivatMartin in forum Excel General
    Replies: 1
    Last Post: 04-09-2013, 12:00 PM
  5. Replies: 3
    Last Post: 10-24-2012, 08:15 PM
  6. Showing A Picture From A List Of Pictures
    By Taislin in forum Excel General
    Replies: 1
    Last Post: 06-25-2012, 03:46 PM
  7. [SOLVED] FS:Pictures/works of art
    By Harry in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 04-30-2005, 08:09 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1