![]() |
|
|
|
#1
|
|||
|
|||
|
How can I add a picture/logo in a word document with VBA at a certain location (in the header) ? |
|
#2
|
||||
|
||||
|
Which header?
Which location?
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
The header was an example of a location. Like when you have a logo in the header and you want to remove it(I know how to do this) and then place a new logo on the same spot.
|
|
#4
|
||||
|
||||
|
If you know how to do it, then set a range to the location of the image you are removing and then insert an image in the range e.g. the following will replace the first inline image in each header footer with the named image.
Code:
Sub ReplaceImage()
Dim oHeader As HeaderFooter
Dim oRng As Range
For Each oHeader In ActiveDocument.Sections(1).Headers
If oHeader.Exists Then
If oHeader.Range.InlineShapes.Count > 0 Then
Set oRng = oHeader.Range.InlineShapes(1).Range
oRng.Text = ""
oRng.InlineShapes.AddPicture _
FileName:="C:\Path\filename.jpg", _
LinkToFile:=False, _
SaveWithDocument:=True
End If
End If
Next oHeader
lbl_Exit:
Set oHeader = Nothing
Set oRng = Nothing
Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#5
|
|||
|
|||
|
thank you this is what I needed!
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to click on one picture, and another picture will be shown?
|
unsvn | Drawing and Graphics | 18 | 09-27-2023 02:36 PM |
Picture content control -> insert picture -> empty?
|
Jaymond Flurrie | Word | 3 | 07-13-2016 07:00 AM |
| Move Picture by picture name, rename picture by picture name | CatMan | PowerPoint | 2 | 04-18-2012 12:21 PM |
| Powerpoint automatically changing picture size when adding a picture (2010) | One_Life | PowerPoint | 7 | 01-20-2012 06:57 AM |
| How To Export A Picture From Word? | abrogard | Drawing and Graphics | 0 | 08-10-2009 06:27 PM |