?
Solved

Macro to insert image signature

Posted on 2011-02-18
9
Medium Priority
?
2,018 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

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 …
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

770 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