Solved

VB open word doc, place picture

Posted on 2009-05-15
3
433 Views
Last Modified: 2012-05-07
I need to open a work document, add a picture (to make it look like letterhead) and the office address in a text box.

need help with code to place the picture.  I can open the document just fine.

Troyo
0
Comment
Question by:toverholt
  • 2
3 Comments
 
LVL 19

Expert Comment

by:dlc110161
ID: 24413654
Are you talking about Word or Works? If Word, the below code should get you started.

Dawn Bleuel
Word MVP
Sub InsertPicture()

Dim appWord As Word.Application

Dim strLetter As String

Dim strTemplatePath As String

Dim strFileName As String
 

Application.ScreenUpdating = False

Set appWord = GetObject(, "Word.Application")

strFileName = "PictureFile.docx"

strTemplatePath = "Q:\BleuelDawn\TestFiles\"

strLetter = strTemplatePath & strFileName
 

appWord.Documents.Open strLetter

ActiveDocument.InlineShapes(1).Range.Select

Selection.Copy

ActiveDocument.Close saveChanges:=wdDoNotSaveChanges

Selection.Paste

End Sub

Open in new window

0
 
LVL 37

Accepted Solution

by:
Joanne M. Orzech earned 500 total points
ID: 24425795
I wouldn't be putting anything in a text box to use as letterhead.

If Dawn's code doesn't work, here's a macro I simply recorded... You obviously have to replace the filename and path of your image, as well as the placeholder text I typed.... but this is a very simple macro.


Sub Letterhead()

ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _

        2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _

        wdAutoFitFixed

'HERE'S WHERE YOU PUT THE PATH NAME OF YOUR IMAGE FILE

    Selection.InlineShapes.AddPicture FileName:= _

        "C:\Documents and Settings\orzechj\My Documents\My Pictures\Clouds.bmp", _

        LinkToFile:=False, SaveWithDocument:=True

    Selection.MoveLeft Unit:=wdCharacter, Count:=1

    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend

    Selection.InlineShapes(1).LockAspectRatio = msoTrue

    Selection.InlineShapes(1).Height = 72#

    Selection.InlineShapes(1).Width = 105.1

    Selection.MoveRight Unit:=wdCharacter, Count:=1

    Selection.MoveRight Unit:=wdCell

    Selection.TypeText Text:="Your Company Name Goes Here"

    Selection.TypeParagraph

    Selection.TypeText Text:="Your Company Address Here"

    Selection.TypeParagraph

    Selection.TypeText Text:="City, State Zip "

    Selection.TypeParagraph

    Selection.TypeText Text:="Country"

    Selection.TypeParagraph

    Selection.TypeText Text:="Phone"

    Selection.TypeParagraph

    Selection.TypeText Text:="Website:"

    Selection.MoveLeft Unit:=wdWord, Count:=6, Extend:=wdExtend

    Selection.HomeKey Unit:=wdStory

    Selection.MoveRight Unit:=wdWord, Count:=3, Extend:=wdExtend

    Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone

    Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone

    Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone

    Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone

    Selection.Borders(wdBorderVertical).LineStyle = wdLineStyleNone

    Selection.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone

    Selection.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone

    Selection.EndKey Unit:=wdStory

    Selection.TypeParagraph

    Selection.HomeKey Unit:=wdStory

    Selection.Tables(1).AutoFitBehavior (wdAutoFitContent)

End Sub

Open in new window

0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 25126945
Great!  Thanks so much.  Glad I was able to help.

Joanne Orzech
MS Word MVP
EE Zone Advisor
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

Suggested Solutions

Title # Comments Views Activity
Always hangs on opening 8 65
Word Template Mail merge with vb.net 4 56
Modify table cell in winword via automation 3 28
copy the content of word to outlook 3 46
The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

932 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

13 Experts available now in Live!

Get 1:1 Help Now