Page 1 of 6 123 ... LastLast
Results 1 to 10 of 57

Thread: VBA to insert a custom image

  1. #1
    Board Regular
    Join Date
    Aug 2018
    Location
    NSW, Australia
    Posts
    944
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default VBA to insert a custom image

    I have code to insert a set image. Could someone tell me how to alter it so it can insert a custom image please?

    Code:
    Sub cmdJakeSig()
        Dim shp As Shape
        Set shp = ThisWorkbook.Worksheets("sheet1").Shapes("textbox4")
            Sheets("Sheet2").Shapes("ImgJ").Copy
            Sheets("sheet1").Paste Destination:=Sheets("sheet1").Cells(1, 1)
            Selection.Top = shp.Top + shp.Height + "50"
        'ActiveSheet.Protect Password:=""
    End Sub

  2. #2
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    South Western NSW
    Posts
    17,812
    Post Thanks / Like
    Mentioned
    18 Post(s)
    Tagged
    2 Thread(s)

    Default Re: VBA to insert a custom image

    Shapes("ImgJ").Copy
    What is this Dave ??
    Are you copying and pasting Textbox4 or the picture "ImgJ" ??
    Last edited by Michael M; Sep 22nd, 2019 at 08:25 PM.
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

  3. #3
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    South Western NSW
    Posts
    17,812
    Post Thanks / Like
    Mentioned
    18 Post(s)
    Tagged
    2 Thread(s)

    Default Re: VBA to insert a custom image

    I think this is what you are trying to do ??
    At least it should get you started
    Code:
    Sub MM1()
    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
           .Left = Sheets("sheet1").Cells(1, 1)
           .Top = Sheets("sheet1").Cells(1, 1)
        End With
    End Sub
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

  4. #4
    Board Regular
    Join Date
    Aug 2018
    Location
    NSW, Australia
    Posts
    944
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA to insert a custom image

    Quote Originally Posted by Michael M View Post
    What is this Dave ??
    Are you copying and pasting Textbox4 or the picture "ImgJ" ??
    ImgJ is the image I am pasting. It is stored on another sheet. I am putting it below textbox4 on sheet1.

  5. #5
    Board Regular
    Join Date
    Aug 2018
    Location
    NSW, Australia
    Posts
    944
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA to insert a custom image

    Textbox 4 could have x number of lines in it.

  6. #6
    Board Regular
    Join Date
    Aug 2018
    Location
    NSW, Australia
    Posts
    944
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA to insert a custom image

    Thanks Michael,

    That worked, just put the image in the centre over 2 pages. I need it left aligned on the first page.

    Here is my code.

    Code:
    Dim fNameAndPath As Variant
    Dim img As Picture, shp As Shape
    Set shp = ThisWorkbook.Worksheets("sheet1").Shapes("textbox4")
    
    fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
    If fNameAndPath = False Then Exit Sub
        Set img = Worksheets("sheet1").Pictures.Insert(fNameAndPath)
        With img
           .Top = shp.Top + shp.Height + "50"
        End With
    Thanks.

  7. #7
    Board Regular
    Join Date
    Aug 2018
    Location
    NSW, Australia
    Posts
    944
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA to insert a custom image

    I worked it out Michael, just added .left = "0" to the end of the with block.

    Thanks

  8. #8
    Board Regular
    Join Date
    Aug 2018
    Location
    NSW, Australia
    Posts
    944
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA to insert a custom image

    How could I change the code so if the image was split between 2 pages, it would move the image to the second page?

  9. #9
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    South Western NSW
    Posts
    17,812
    Post Thanks / Like
    Mentioned
    18 Post(s)
    Tagged
    2 Thread(s)

    Default Re: VBA to insert a custom image

    What is the relationship between txtbox 4 and the inserted shape ??
    Why not simply place the new image

    Code:
    Sub MM1()
    Dim fNameAndPath As Variant
    Dim img As Picture, shp As Shape
    Set shp = Worksheets("sheet1").Shapes("textbox 4")
    fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
    If fNameAndPath = False Then Exit Sub
        Set img = Worksheets("sheet1").Pictures.Insert(fNameAndPath)
        With img
           .Left = 0
           .Top = shp.Top + shp.Height + 50
        End With
    End Sub
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

  10. #10
    Board Regular
    Join Date
    Aug 2018
    Location
    NSW, Australia
    Posts
    944
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA to insert a custom image

    Quote Originally Posted by Michael M View Post
    What is the relationship between txtbox 4 and the inserted shape ??
    Textbox4 is a notes text box and the inserted image is a signature that must be a set distance from the bottom of the notes.

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
  •