Solved

Macro to insert image signature

Posted on 2011-02-18
9
1,915 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
  • 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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…

828 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