Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 4th, 2007, 05:34 AM
Registered User
 
Join Date: Apr 2007
Location: London, London, United Kingdom.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to insert in image in a header programatically

I created a form in Access 2000 the function of which is to create an Access report.

One thing that I want it to is to write the report into a Word document and this I do with the Access Outputto method. There are no problems up this point.

However, what I also want to do is to insert the comapny's logo in the header of the newly created Word document at the same time ie programmatically, rather by manually copying and pasting the image in.

I need to use the Word object model but, despite looking for quite sometime I cannot find an appropriate method. Unfortunately I have very little to do normally with Word VBA and so I need to ask for some help

Am I asking for the impossible?


Any advice will be greatly appreciated.





Michael109


:)

Michael109
Reply With Quote
  #2 (permalink)  
Old April 4th, 2007, 06:51 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Here you have

Sub Word_Insert_Image_in_Header()

Dim oWD As Word.Document

Set oWD = ActiveDocument

    With oWD.Sections(1)
        .Headers(wdHeaderFooterPrimary).Range.Text = "Text as Header"
        .Headers(wdHeaderFooterPrimary).Range.InlineShapes .AddPicture "c:\simulation.jpg"
    End With

End Sub

Cheers
Shasur:)

http://www.vbadud.blogspot.com
Reply With Quote
  #3 (permalink)  
Old April 4th, 2007, 09:41 AM
Registered User
 
Join Date: Apr 2007
Location: London, London, United Kingdom.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I forgot to mention that I was accessing the Word document from Access VBA. All that needs to be added is the creation of a word application object so that one can access the relevant file with the correct file path. I didn't use the ActiveDocument constant but

Set oWD = Word.Documents.Open("C:\MyFilePath.doc")

The code now works in the way that I want it to.

Many thanks. It is much appreciated



:):D:D:)

Michael109
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to center the header image kherrerab BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 May 29th, 2010 11:51 PM
Multiple Image Header Layout rodmcleay CSS Cascading Style Sheets 5 March 22nd, 2008 06:31 PM
Inserting an image in the header of a word documen Michael109 Access 3 April 4th, 2007 11:26 AM
Placing Image in Header Section Of Crystal Report B.V.Madhav BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 0 May 9th, 2005 02:44 AM
changing image/logo in report header h_haviv Crystal Reports 1 February 27th, 2005 07:59 PM



All times are GMT -4. The time now is 02:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.