Results 1 to 3 of 3

Thread: VB Code to resize an image
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Dec 2018
    Posts
    108
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default VB Code to resize an image



    New
    This code I am using but the issue is width of picture, it is not fixing in A34:C34 and stretching it all the way to Column P

    Please please help

    Sub GetPic()
    Dim fNameAndPath As Variant
    Dim img As Picture
    fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
    If fNameAndPath = False Then Exit Sub
    Set img = ActiveSheet.Pictures.Insert(fNameAndPath)
    With img
    'Resize Picture to fit in the range....
    .Left = ActiveSheet.Range("A34").Left
    .Top = ActiveSheet.Range("A34").Top
    .Width = ActiveSheet.Range("A34:C34").Width
    .Height = ActiveSheet.Range("A34:A48").Height
    .Placement = 1
    .PrintObject = True
    End With
    End Sub



  2. #2
    Board Regular
    Join Date
    Jan 2014
    Location
    Dublin, Ireland
    Posts
    1,421
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VB Code to resize an image

    It worked for me when i switched the width with the height. Can you try that?

    Code:
    Sub GetPic()
    Dim fNameAndPath As Variant
    Dim img As Picture
    fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
    If fNameAndPath = False Then Exit Sub
    Set img = ActiveSheet.Pictures.Insert(fNameAndPath)
    With img
    'Resize Picture to fit in the range....
    .Left = ActiveSheet.Range("A34").Left
    .Top = ActiveSheet.Range("A34").Top
    .Height = ActiveSheet.Range("A34:A48").Height
    .Width = ActiveSheet.Range("A34:C34").Width
    .Placement = 1
    .PrintObject = True
    End With
    End Sub
    Learn something new everyday.

    be sure to use code tags

    Code:
    [ code ]
    [ / code ]
    ' no spaces

  3. #3
    Board Regular
    Join Date
    Dec 2018
    Posts
    108
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VB Code to resize an image

    Thanks dear, yes width issue now resolved but now height issue is there like now height is reduced with cell A34:C38
    IT SHOULD BE A34:C48

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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