Results 1 to 3 of 3

How do I resize an inserted image in a cell?

Threaded View

  1. #1
    Registered User
    Join Date
    12-16-2012
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    19

    How do I resize an inserted image in a cell?

    Hi all,
    I have a problem that is driving me crazy. I'm pretty new to VBA/Macros. I have managed to get the macro working to insert a specific jpeg image into the right cell 'W28', however I don't know how to resize the image so that it doesn't cross over the cell borders, which it currently does. The macro is linked to a command button. There will be a few buttons, each one inserting a different signature depending on the user. Once I have the first one sorted, then it will be straight forward to do the others. Here is the code I currently have;

    Sub InsertPictureIG()
        InsertPictureAInRange "C:\Users\Chief Engineer\Documents\Engine Room Log\Signatures\Benn Signature.jpg", _
        Range("W28")
    End Sub
    Sub InsertPictureAInRange(PictureFileName As String, TargetCells As Range)
         ' inserts a picture and resizes it to fit the TargetCells range
        Dim p As Object, t As Double, l As Double, w As Double, h As Double
        If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
        If Dir(PictureFileName) = "" Then Exit Sub
         ' import picture
        Set p = ActiveSheet.Pictures.Insert(PictureFileName)
         ' determine positions
        With TargetCells
            t = .Top
            l = .Left
            w = .Offset(0, .Columns.Count).Left - .Left
            h = .Offset(.Rows.Count, 0).Top - .Top
        End With
         ' position picture
        With p
            .Top = t
            .Left = l
            .Width = w
            .Height = h
        End With
        Set p = Nothing
    End Sub
    Can someone please help me on this?

    Thanks,
    Benn
    Last edited by arlu1201; 12-16-2012 at 02:07 PM.

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