Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert picture and text at beginning of document

Status
Not open for further replies.

BitZero

Programmer
Mar 11, 2008
100
US
I'm trying to do the following with VBA code:

Open an existing word document
Insert a picture (company logo) from a jpg file at the top left of page 1
Insert text (company name and address) at the top right of page 1
Format the text (bold, font, etc)

What is the command to move to the beginning of page 1?
How can I position the text to start at a particular line and column?

When I use the macro recorder, a lot of the commands start with "selection." What commands can I use to set the "selection" range?

Any sample code would be appreciated.

 


Hi,

Please post your code as it stands, for help going forward.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi Skip

This code is from the macro recorder. How do I control exactly where the picture and text are placed?

Code:
    Selection.MoveUp Unit:=wdLine, Count:=9
    Selection.InlineShapes.AddPicture FileName:= _
        "c:\MyStuff\Logo_Acme_Bolts.png", LinkToFile:= _
        False, SaveWithDocument:=True
    Selection.TypeParagraph
    Selection.TypeText Text:="Acme Bolts"
    Selection.TypeParagraph
    Selection.TypeText Text:="123 Main St."
    Selection.TypeParagraph
    Selection.TypeText Text:="New York, NY 12345"
    Selection.TypeParagraph
    Selection.TypeText Text:="(111) 222-3333"
    Selection.TypeParagraph

 

Some time ago I had similar problem. I ended up creating a small template in Word where I placed the company logo and needed text, aligned it, made it ‘pretty’ and had it ready to go. It was a lot easier to deal with that do it every time in the code.

Plus, that gave me the basis to create a whole bunch of letters in Word where I placed bookmarks and then I could place information from my database in the letters.

Just the suggestion….


Have fun.

---- Andy
 



try this...
Code:
    Dim MyRng As Range
    
    Set MyRng = ThisDocument.Content
    
    MyRng.Collapse wdCollapseStart
    
    MyRng.Select
    
    With Selection
        .MoveUp Unit:=wdLine, Count:=9
            .InlineShapes.AddPicture FileName:= _
                "c:\MyStuff\Logo_Acme_Bolts.png", LinkToFile:= _
                False, SaveWithDocument:=True
        
        .TypeParagraph
        .TypeText Text:="Acme Bolts"
        .TypeParagraph
        .TypeText Text:="123 Main St."
        .TypeParagraph
        .TypeText Text:="New York, NY 12345"
        .TypeParagraph
        .TypeText Text:="(111) 222-3333"
        .TypeParagraph
    End With

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks Skip and Andy

One more question Skip: how do I position the text to the top right of the page? The code above puts the text under the picture.
 



Then you do not want an InLine Shape for your picture.

Check out the other Text Wrapping options and determine what will work the best for you.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Sorry - I'm still confused. InlineShapes is a property of a range object. What property do I use for "text wrapping options"?
 



Check out the Shapes Collection Object. Notice the explanation of the diference between InLine Shape and Shape objects.

Do you exploration in your document, not in VBA. Then Macro record.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top