Solved

Macro to insert image signature

Posted on 2011-02-18
9
1,855 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
 

Author Comment

by:jlspencer
ID: 34961005





Basically  a Sign Here_____________________

With the cursor a space or two to the right of "here"
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
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…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

746 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now