Solved

Macro to insert image signature

Posted on 2011-02-18
9
1,971 Views
Last Modified: 2012-05-11
I use the following code from a previous question of mine to EE, the code works except for one thing. When you want to insert the code next to  or on a Line in word it displaces the existing line and inserts the picture to the left of existing line or text. Is there a way to mesh existing text and the signature image?


Sub Signature()
'
' Signature Macro
'
'
With ActiveDocument
        .InlineShapes.AddPicture "C:\Document\Templates\Formal.bmp", LinkToFile:=False, SaveWithDocument:=True
     
    End With
End Sub
0
Comment
Question by:jlspencer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 4

Expert Comment

by:jmdion
ID: 34928865
By using Shapes instead of InlineShapes you will get a "floating" picture that will not displace the text.

But the you have the problem of positioning the image by adjusting Left and Top.  If you don't use the Anchor parameter the position will be relative to the page.
With ActiveDocument
    
        .Shapes.AddPicture _
            FileName:="C:\signature.bmp", _
            LinkToFile:=False, _
            SaveWithDocument:=True, _
            Left:=InchesToPoints(0.5), _
            Top:=InchesToPoints(2), _
            Anchor:=Selection.Range
      
    End With

Open in new window

0
 

Author Comment

by:jlspencer
ID: 34960703
This works but does not place the image at the location of the cursor.
0
 
LVL 4

Expert Comment

by:jmdion
ID: 34960903
A sample document of the desired results would help to make clear what the code should accomplish.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:jlspencer
ID: 34961005





Basically  a Sign Here_____________________

With the cursor a space or two to the right of "here"
0
 

Author Comment

by:jlspencer
ID: 34961019
Keep in mind that this could be located at the users discretion
0
 
LVL 4

Expert Comment

by:jmdion
ID: 34961128
Can it be done manually?
0
 

Author Comment

by:jlspencer
ID: 34984637
Right now the signature image inserts well above the cursor location
0
 
LVL 4

Accepted Solution

by:
jmdion earned 500 total points
ID: 34989131
Got it!

The trick was to change Top and Left after setting RelativeVerticalPosition and RelativeHorizontalPosition.
Sub InsertSignature()
    Dim myShape As Shape
    
    Set myShape = ActiveDocument.Shapes.AddPicture _
        (FileName:="c:\users\public\signature.bmp", _
        LinkToFile:=False, _
        SaveWithDocument:=True, _
        Anchor:=Selection.Range)
        
    myShape.height = 32
    
    myShape.RelativeVerticalPosition = wdRelativeVerticalPositionLine
    myShape.RelativeHorizontalPosition = wdRelativeHorizontalPositionCharacter
    
    myShape.Top = -myShape.height + 12
    myShape.Left = 10
    
    ' If image is GIF or PNG with transparency then you don't need this
    myShape.PictureFormat.TransparentBackground = msoTrue
    myShape.PictureFormat.TransparencyColor = RGB(255, 255, 255)
    ' And if white part of image is not exactly white then use this
    ' myShape.ZOrder msoSendBehindText
    
End Sub

Open in new window

0
 

Author Closing Comment

by:jlspencer
ID: 34996642
We have a winner...Thank you
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question