+ Reply to Thread
Results 1 to 4 of 4

Inserting Pictures

  1. #1
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Inserting Pictures

    Using a Macro I need to insert various jpg pictures into an Excel sheet.

    These pictures are various sizes and need to be resized to the same size.

    Using VBA Is is possible to size a picture to a specific size? or to get its current size and then calculate the % scaling required.


    thanks in advance

  2. #2
    Greg Wilson
    Guest

    RE: Inserting Pictures

    Try:

    Sub InsertPicts()
    Dim P As Picture
    Dim FNm As Variant
    Dim R As Single
    Dim c As Range

    Set c = Cells(3, 3)
    With Application
    FNm = .GetOpenFilename("Picture files(*.jpg), *.jpg")
    If VarType(FNm) = vbBoolean Then Exit Sub
    .ScreenUpdating = False
    Set P = ActiveSheet.Pictures.Insert(FNm)
    R = P.Width / P.Height
    P.Top = c.Top
    P.Left = c.Left
    P.Height = 350
    P.Width = R * P.Height 'correct proportionality after resizing
    .ScreenUpdating = True
    End With
    End Sub

    Pictures are now "Hidden Members" and we're supposed to use the shape
    object's AddPicture method. The problem with AddPicture is that the height
    and width properties are required arguments. So how does one know the
    appropriate proportionality since picture files come in different shapes and
    sizes ? I know I'm missing something here and am quite interested if someone
    has the answer.

    Regards,
    Greg

    "mudraker" wrote:

    >
    > Using a Macro I need to insert various jpg pictures into an Excel
    > sheet.
    >
    > These pictures are various sizes and need to be resized to the same
    > size.
    >
    > Using VBA Is is possible to size a picture to a specific size? or to
    > get its current size and then calculate the % scaling required.
    >
    >
    > thanks in advance
    >
    >
    > --
    > mudraker
    > ------------------------------------------------------------------------
    > mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
    > View this thread: http://www.excelforum.com/showthread...hreadid=531391
    >
    >


  3. #3
    David McRitchie
    Guest

    Re: Inserting Pictures

    Why not just do it with a photo editor in batch mode beforehand, you can do that with
    IrfanView (irfanview.com) and many other free applications.
    ---
    HTH,
    David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
    My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
    Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

    "mudraker" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Using a Macro I need to insert various jpg pictures into an Excel
    > sheet.
    >
    > These pictures are various sizes and need to be resized to the same
    > size.
    >
    > Using VBA Is is possible to size a picture to a specific size? or to
    > get its current size and then calculate the % scaling required.
    >
    >
    > thanks in advance
    >
    >
    > --
    > mudraker
    > ------------------------------------------------------------------------
    > mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
    > View this thread: http://www.excelforum.com/showthread...hreadid=531391
    >




  4. #4

    Re: Inserting Pictures

    This a code written in VB.net.
    In searches for all BMP files in the folder, resize it and save it to
    JPEG.

    Hope this will help.


    Sub Main()
    Dim objFile As FileInfo
    Dim objFolder As New DirectoryInfo("C:\Photo\BMP")
    Dim objFolderFI As FileInfo() = objFolder.GetFiles("*.bmp")
    Dim jpgFileName As String

    For Each objFile In objFolderFI
    Dim objBMP As New Bitmap("C:\Photo\BMP\" & objFile.Name)
    objBMP = New Bitmap(objBMP, New Size(150, 150))
    jpgFileName = Left(objFile.Name, Len(objFile.Name) - 3) &
    "jpg"
    Console.WriteLine("Converting C:\Photo\BMP\" &
    objFile.Name)
    objBMP.Save("C:\Photo\JPG\" & jpgFileName,
    ImageFormat.Jpeg)
    Next
    End Sub


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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