Solved

Macro to insert image signature

Posted on 2011-02-18
9
1,877 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

911 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

20 Experts available now in Live!

Get 1:1 Help Now