Replace exisiting image programatically.

D

Dan Kelly

Our current letter template has our logo defined in a specific position in
the document header. The logo is an image file (let's say .gif) that has
been placed on the template.

My PR department has requested that we allow users to choose the colour of
the logo that will appear on their documents.

I can easily give the users a dialog to pick the correct colour .gif of the
logo, what I cannot work out is how to place that image in the position of
the exisiting logo.

The options that I can see are:

1) Replace the exisiting .gif logo with my choice

2) Replace the image in the template with a bookmark

3) Replace the image with a Text Box and insert into that.

4) Have a different colour template for each logo.

We are using Office 2000. Any suggestions or recommendations?
 
J

Jean-Guy Marcil

Dan Kelly was telling us:
Dan Kelly nous racontait que :
Our current letter template has our logo defined in a specific
position in the document header. The logo is an image file (let's
say .gif) that has been placed on the template.

My PR department has requested that we allow users to choose the
colour of the logo that will appear on their documents.

I can easily give the users a dialog to pick the correct colour .gif
of the logo, what I cannot work out is how to place that image in the
position of the exisiting logo.

The options that I can see are:

1) Replace the exisiting .gif logo with my choice

2) Replace the image in the template with a bookmark

3) Replace the image with a Text Box and insert into that.

4) Have a different colour template for each logo.

We are using Office 2000. Any suggestions or recommendations?

I would use a bookmark to mark the location of the logo in the header and
would use an inline shape. Then, with code like this, users could change the
logo at will:

Sub InsertPix()
'Use whatever bookmark name you want, make sure the one in the code is
accurate
Const strBmkName As String = "bmkLogo"
Dim rgeInsertFile As Range
Dim strFileFullName As String

'You may have to change the section # or the type of header
Set rgeInsertFile = ActiveDocument.Sections(1). _
Headers(wdHeaderFooterPrimary).Range.Bookmarks(strBmkName).Range

'-2 = Close
'-1 = OK
'0 = Cancel
'>0 = Other buttons
With Dialogs(wdDialogInsertPicture)
Select Case .Display
Case 0
MsgBox "Cancelled by user.", vbInformation, "Cancelled"
Exit Sub
Case -1
strFileFullName = WordBasic.FileNameInfo$(.Name, 1)
End Select
End With

With rgeInsertFile
.Delete
'change the options as you want so that the logo may be linked, saved
with the file or not...
'See the online help for AddPicture for more info
.InlineShapes.AddPicture FileName:=strFileFullName, _
LinkToFile:=False
.MoveEnd wdCharacter, 1
End With

'Recreate the bookmark
ActiveDocument.Bookmarks.Add strBmkName, rgeInsertFile

End Sub


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top