Results 1 to 13 of 13

Thread: Signature

  1. #1

    Lightbulb Signature

    Hi all,

    The code below inserts a Signature .png image into a word document at a bookmark called "signature". This works fine if the signature is the last shape in the document. If it is not the last shape then it selects the last shape instead. I would appreciate any direction as to how to resize the signature .png image as soon as it is added to the bookmark location.

    Sub AddSignaturePNG()
    
    
        Application.ScreenUpdating = False
    
    
      'call the signature file
    
      Call FillABookmarkX("signature", "c:\Signature\Signature.png")
        
        'Resize the added signature
        PicResizeX
        
        Application.ScreenUpdating = True
    
    
            
    End Sub
    
    
    Sub FillABookmarkX(strBM As String, strText As String)
        
        
        Dim j As Long
        With ActiveDocument
            .Bookmarks(strBM).Range _
            .InlineShapes _
            .AddPicture FileName:=strText
            
               
            j = ActiveDocument.InlineShapes.Count
            .InlineShapes(j).Select
            
            .Bookmarks.Add strBM, Range:=Selection.Range
            
        End With
        
    End Sub
    
    
    Sub PicResizeX()
         Dim PecentSize As Integer
    
    
         PercentSize = 7
    
    
         If Selection.InlineShapes.Count > 0 Then
             Selection.InlineShapes(1).ScaleHeight = PercentSize
             Selection.InlineShapes(1).ScaleWidth = PercentSize
         Else
             Selection.ShapeRange.ScaleHeight Factor:=(PercentSize / 100), _
               RelativeToOriginalSize:=msoCTrue
             Selection.ShapeRange.ScaleWidth Factor:=(PercentSize / 100), _
               RelativeToOriginalSize:=msoCTrue
         End If
     End Sub

  2. #2
    7% seems very small? However
    Option Explicit
    
    Sub AddSignaturePNG()
        Application.ScreenUpdating = False
         'call the signature file
        Call FillABookmarkX("signature", "c:\Signature\Signature.png")
        Application.ScreenUpdating = True
    End Sub
     
     
    Sub FillABookmarkX(strBM As String, strText As String)
        Dim oShape As InlineShape
        With ActiveDocument
            Set oShape = .Bookmarks(strBM).Range _
            .InlineShapes _
            .AddPicture(Filename:=strText)
            PicResizeX oShape
            oShape.Select
            .Bookmarks.Add strBM, Range:=Selection.Range
        End With
    End Sub
    
    
    Sub PicResizeX(oShape As InlineShape)
    Dim PercentSize As Integer
        PercentSize = 7
        oShape.ScaleHeight = PercentSize
        oShape.ScaleWidth = PercentSize
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,411
    Location
    Private m_oILS As InlineShape
    Sub AddSignaturePNG()
      FillABookmarkX "signature", "D:\Signature.png"
      With m_oILS
        .ScaleHeight = 7
        .ScaleWidth = 7
      End With
    End Sub
     
    Sub FillABookmarkX(strBM As String, strFile As String)
      Set m_oILS = ActiveDocument.Bookmarks("signature").Range.InlineShapes.AddPicture(strFile)
      ActiveDocument.Bookmarks.Add strBM, m_oILS.Range
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  4. #4
    Hi Gmayor,

    I owe you a pint, that worked perfectly thank you very much indeed! I am marking this thread as solved.

    Des

  5. #5
    Hi Greg,

    First of all, thanks for the reply. I tried your solution also and it is throwing a variable not defined error for "m_oILS". What should I define "m_oILS" as?

    Cheers,

    Des

    Quote Originally Posted by gmaxey View Post
    Private m_oILS As InlineShape
    Sub AddSignaturePNG()
      FillABookmarkX "signature", "D:\Signature.png"
      With m_oILS
        .ScaleHeight = 7
        .ScaleWidth = 7
      End With
    End Sub
     
    Sub FillABookmarkX(strBM As String, strFile As String)
      Set m_oILS = ActiveDocument.Bookmarks("signature").Range.InlineShapes.AddPicture(strFile)
      ActiveDocument.Bookmarks.Add strBM, m_oILS.Range
    End Sub

  6. #6
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,411
    Location
    m_oILS is declared at the module level as shown e.g.m Private m_oILS as InlineShape

    It is declared at the module level because it is used in both procedures.
    Greg

    Visit my website: http://gregmaxey.com

  7. #7
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,411
    Location
    There are all kinds of ways you can do this. Here is one that doesn't use any declared variables:

    Sub AddSignaturePNG()
      With fcnStuffPictureInBookmark("signature", "D:\Signature.png")
        .ScaleHeight = 7
        .ScaleWidth = 7
      End With
    End Sub
    
    Function fcnStuffPictureInBookmark(strBM As String, strFile As String) As InlineShape
      Set fcnStuffPictureInBookmark = ActiveDocument.Bookmarks("signature").Range.InlineShapes.AddPicture(strFile)
      ActiveDocument.Bookmarks.Add strBM, fcnStuffPictureInBookmark.Range
    End Function
    Greg

    Visit my website: http://gregmaxey.com

  8. #8
    Hi Greg,

    My bad, I completely missed that. Both of the solutions worked perfectly for me so marking this thread as solved.

    Thanks again,

    Des

    Quote Originally Posted by gmaxey View Post
    m_oILS is declared at the module level as shown e.g.m Private m_oILS as InlineShape

    It is declared at the module level because it is used in both procedures.

  9. #9
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,411
    Location
    You're welcome. Do I not get a pint?
    Greg

    Visit my website: http://gregmaxey.com

  10. #10
    Greg,

    I will gladly buy you a creamy dreamie!

    Cheers,

    Des

    Quote Originally Posted by gmaxey View Post
    You're welcome. Do I not get a pint?

  11. #11
    I had marked this thread as solved but I was wondering if the code could be modified so that you didn't need to put a bookmark in but rather the signature would go where the cursor was active? No problem if I need to open a new thread I'm not sure of the protocol.

    Thanks

    Quote Originally Posted by gmaxey View Post
    There are all kinds of ways you can do this. Here is one that doesn't use any declared variables:

    Sub AddSignaturePNG()
      With fcnStuffPictureInBookmark("signature", "D:\Signature.png")
        .ScaleHeight = 7
        .ScaleWidth = 7
      End With
    End Sub
    
    Function fcnStuffPictureInBookmark(strBM As String, strFile As String) As InlineShape
      Set fcnStuffPictureInBookmark = ActiveDocument.Bookmarks("signature").Range.InlineShapes.AddPicture(strFile)
      ActiveDocument.Bookmarks.Add strBM, fcnStuffPictureInBookmark.Range
    End Function

  12. #12
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,411
    Location
    Sub AddSignaturePNG()
        With fcnStuffPictureAsSelection("signature", "D:\Signature.png")
            .ScaleHeight = 7
            .ScaleWidth = 7
        End With
    End Sub
     
    Function fcnStuffPictureAsSelection(strBM As String, strFile As String) As InlineShape
        Set fcnStuffPictureAsSelection = Selection.Range.InlineShapes.AddPicture(strFile)
    End Function
    Greg

    Visit my website: http://gregmaxey.com

  13. #13
    Greg,

    That fits my needs perfectly. Thanks very much indeed.

    Des

    Quote Originally Posted by gmaxey View Post
    Sub AddSignaturePNG()
        With fcnStuffPictureAsSelection("signature", "D:\Signature.png")
            .ScaleHeight = 7
            .ScaleWidth = 7
        End With
    End Sub
     
    Function fcnStuffPictureAsSelection(strBM As String, strFile As String) As InlineShape
        Set fcnStuffPictureAsSelection = Selection.Range.InlineShapes.AddPicture(strFile)
    End Function

Posting Permissions

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