INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Adding a logo image to word documents

Adding a logo image to word documents

(OP)

Hi,
Could anyone advise how I can use VBA (which would be included in an Excel VBA module) to add the same logo image to the front page of number of word documents that are stored in a folder
eg
  • select the folder where the word docs are stored
  • open the word docs one at a time
  • add the logo to the front page in a specific position
  • save the word doc
  • close the word doc
Many thanks in advance

Regards

Pete

RE: Adding a logo image to word documents

For that you might use a macro like:

CODE

Sub UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String
Dim wdDoc As Document, strDocNm As String
Const StrPic As String = "C:\Path\FileName.ext"
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, _
      AddToRecentFiles:=False, Visible:=False)
    With wdDoc
      .Shapes.AddPicture FileName:=StrPic, _
        Left:=InchesToPoints(1), _
        Top:=InchesToPoints(1), _
        Height:=InchesToPoints(3), _
        Width:=InchesToPoints(2)
      .Close SaveChanges:=True
    End With
  End If
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function 
replacing 'C:\Path\FileName.ext' with the full name & path of your image and using the various InchesToPoints settings to define the image's size & position in inches.

For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm

The macro includes a folder browser that lets you select the document folder you want to process.

Cheers
Paul Edstein
[MS MVP - Word]

RE: Adding a logo image to word documents

(OP)
Hi Paul,

Excellent - Many thanks for your swift reply - I'll have a look at the content

Best Regards

peter

RE: Adding a logo image to word documents

peterpcu,

Did the code work for your situation? Did you have any issues implementing it or using pieces of it?

macropod,

Any reason to use the Dir() function for looping through files rather than the FileSystemObject? Just curious, as I've used the FileSystemObject for practically every instance of looping through files.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57

RE: Adding a logo image to word documents

Quote:

Any reason to use the Dir() function for looping through files rather than the FileSystemObject?
Because it's simple and effective, with none of the FSO overhead.

Cheers
Paul Edstein
[MS MVP - Word]

RE: Adding a logo image to word documents

OK, that's what I thought, and I definitely see the less overhead portion. FSO just gives more flexibility, at least where I've used the two. Either more flexibility or just plain easier to code.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57

RE: Adding a logo image to word documents

Dir isn't reentrant, so it is less useful if you are writing a typical recursive directory walk ...

RE: Adding a logo image to word documents

Gotcha - yeah, that's how I've used it vs FSO. If just a quick action or something, I'll use Dir(), but if I need to do something multiple times with something like "all files of type X in a folder" or especially if need search subfolders, I'll use FSO.

Thanks for the thoughts.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close