Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-02-2017, 02:56 PM
elbartje elbartje is offline Add a picture in word Windows 10 Add a picture in word Office 2016
Novice
Add a picture in word
 
Join Date: Jun 2017
Posts: 4
elbartje is on a distinguished road
Default Add a picture in word


How can I add a picture/logo in a word document with VBA at a certain location (in the header) ?
Reply With Quote
  #2  
Old 06-02-2017, 08:01 PM
gmayor's Avatar
gmayor gmayor is offline Add a picture in word Windows 10 Add a picture in word Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 06-02-2017, 11:57 PM
elbartje elbartje is offline Add a picture in word Windows 10 Add a picture in word Office 2016
Novice
Add a picture in word
 
Join Date: Jun 2017
Posts: 4
elbartje is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 06-03-2017, 12:18 AM
gmayor's Avatar
gmayor gmayor is offline Add a picture in word Windows 10 Add a picture in word Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #5  
Old 06-05-2017, 09:32 AM
elbartje elbartje is offline Add a picture in word Windows 10 Add a picture in word Office 2016
Novice
Add a picture in word
 
Join Date: Jun 2017
Posts: 4
elbartje is on a distinguished road
Default

thank you this is what I needed!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add a picture in word How to click on one picture, and another picture will be shown? unsvn Drawing and Graphics 18 09-27-2023 02:36 PM
Add a picture in word 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:58 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft