Results 1 to 4 of 4

Thread: auto size the jpeg files into excel while importing and inserting pictures

  1. #1
    Join Date
    Dec 2011
    Posts
    61

    auto size the jpeg files into excel while importing and inserting pictures

    Is there an add-in that will auto size a picture within a specified area without having to resize it all the time. I'm trying to design my own trading journal and need to import screen shots saved as jpeg file into a specified area. Any help would be greatly appreciated.

  2. #2
    Join Date
    Jun 2011
    Posts
    635

    Re: auto size the jpeg files into excel while importing and inserting pictures

    You need to read, for example, the width of both the range where you are pasting, and the width of
    the jpg:

    With ActiveSheet
    'Select the cell where the picture is placed
    Range("rngForJPG").Cells(1,1).Select
    'Insert the picture
    .Pictures.Insert(myImageFileName).Select
    'scale the picture to the width of the column
    myScale = Range("rngForJPG").Cells(1,1).EntireColumn.Width / Selection.ShapeRange.Width
    Selection.ShapeRange.ScaleWidth myScale, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleHeight myScale, msoFalse, msoScaleFromTopLeft
    'Change the row height to the picture height
    Range("rngForJPG").Cells(1,1).EntireRow.RowHeight = Selection.ShapeRange.Height
    End With
    This may help you out.

  3. #3
    Join Date
    Jul 2011
    Posts
    634

    Re: auto size the jpeg files into excel while importing and inserting pictures

    Select the cells (either manually or in code) where you want the picture to go, and then run this macro.

    Sub InsertAndResizePicture()
    Dim myR As Range
    Set myR = Selection
    'Insert the picture
    ActiveSheet.Pictures.Insert( _Application.GetOpenFilename( _
    "JPG picture files (*.jpg),*.jpg", , "Select the picture")).Select
    'scale the picture to the width of the column
    myScale = Application.Min(myR.Width / Selection.ShapeRange.Width, _
    myR.Height / Selection.ShapeRange.Height)
    Selection.ShapeRange.ScaleWidth myScale, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleHeight myScale, msoFalse, msoScaleFromTopLeft
    myR.select

    End Sub


    You of course can modify it to choose the range and filenames in code...


    Sub InsertAndResizePicture2()

    Dim myR As Range
    Set myR = Range("Range_Name")
    'Insert the picture
    ActiveSheet.Pictures.Insert( "C:\PictureFiles\Picture1.jpg").Select
    'scale the picture to the width of the column
    myScale = Application.Min(myR.Width / Selection.ShapeRange.Width, _
    myR.Height / Selection.ShapeRange.Height)
    Selection.ShapeRange.ScaleWidth myScale, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleHeight myScale, msoFalse, msoScaleFromTopLeft
    myR.Select
    End Sub

  4. #4
    Join Date
    Jun 2011
    Posts
    798

    Re: auto size the jpeg files into excel while importing and inserting pictures

    You of course can modify it to choose the range and filenames in code.

    Sub InsertAndResizePicture2()
    Dim myR As Range
    Set myR = Range("Range_Name")
    'Insert the picture
    ActiveSheet.Pictures.Insert( "C:\PictureFiles\Picture1.jpg").Select
    'scale the picture to the width of the column
    myScale = Application.Min(myR.Width / Selection.ShapeRange.Width, _
    myR.Height / Selection.ShapeRange.Height)
    Selection.ShapeRange.ScaleWidth myScale, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleHeight myScale, msoFalse, msoScaleFromTopLeft
    myR.Select
    End Sub

Similar Threads

  1. Inserting a Row at the end of a Table in Microsoft Excel
    By Ramanujan in forum MS Office Support
    Replies: 2
    Last Post: 01-02-2012, 02:06 PM
  2. Auto resize images while importing in Microsoft Excel
    By SirName in forum Windows Software
    Replies: 3
    Last Post: 21-01-2012, 01:01 PM
  3. How to open pictures with jpeg extension using getfolderitem?
    By emMetTi in forum Software Development
    Replies: 6
    Last Post: 27-07-2011, 08:20 PM
  4. Inserting an gif file in Excel
    By Bassus in forum Windows Software
    Replies: 7
    Last Post: 17-03-2010, 08:16 PM
  5. How to make size of jpeg files smaller
    By Beneficence in forum Customize Desktop
    Replies: 4
    Last Post: 17-02-2009, 11:08 PM

Tags for this Thread

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
  •  
Page generated in 1,713,566,791.66643 seconds with 17 queries