Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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
 
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
 
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




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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.