Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Wed, 12 Mar 2008 07:29:04 -0700,    group: microsoft.public.word.vba.customization        back       


Adding an image to headers dynamically using VBA Word   
Hi,
 I've been having the hardest time adding an image to a header in word using 
VBA Word. Below is the following code that I'm using to add an image to the 
header. In full I want to have the ability to add to the header and footer 
for each page.


docActive.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
docActive.Sections(1).Headers(1).InlineShapes.AddPicture sFileName, False, 
true
With docActive.PageSetup
    .DifferentFirstPageHeaderFooter = False 'Set this to false will put text 
on first page, else will not.
End With
date: Wed, 12 Mar 2008 07:29:04 -0700   author:   Brandon M. Hunter Brandon M.

Re: Adding an image to headers dynamically using VBA Word   
Why don't you start with a template that already contains the image? (and 
use code to delete it if there are some occasions when you do not want it.)

-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Brandon M. Hunter" <Brandon M. Hunter@discussions.microsoft.com> wrote in 
message news:3787A7AE-C934-4CD5-80F3-747551387193@microsoft.com...
> Hi,
> I've been having the hardest time adding an image to a header in word 
> using
> VBA Word. Below is the following code that I'm using to add an image to 
> the
> header. In full I want to have the ability to add to the header and footer
> for each page.
>
>
> docActive.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> docActive.Sections(1).Headers(1).InlineShapes.AddPicture sFileName, False,
> true
> With docActive.PageSetup
>    .DifferentFirstPageHeaderFooter = False 'Set this to false will put 
> text
> on first page, else will not.
> End With
>
date: Thu, 13 Mar 2008 05:54:00 +1000   author:   Doug Robbins - Word MVP

Re: Adding an image to headers dynamically using VBA Word   
I've tried and it doesn't work when it comes to adding the image to the 
header or footer. That would be nice, but all the code that I've tried, 
fails. Do you have any sample code that I take a look at, or maybe help me 
out with the code I posted. I've been at this for about 2 days. I can add 
text to both the header and footer, but I can't add images.

"Doug Robbins - Word MVP" wrote:

> Why don't you start with a template that already contains the image? (and 
> use code to delete it if there are some occasions when you do not want it.)
> 
> -- 
> Hope this helps.
> 
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
> 
> Doug Robbins - Word MVP
> 
> "Brandon M. Hunter" <Brandon M. Hunter@discussions.microsoft.com> wrote in 
> message news:3787A7AE-C934-4CD5-80F3-747551387193@microsoft.com...
> > Hi,
> > I've been having the hardest time adding an image to a header in word 
> > using
> > VBA Word. Below is the following code that I'm using to add an image to 
> > the
> > header. In full I want to have the ability to add to the header and footer
> > for each page.
> >
> >
> > docActive.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> > docActive.Sections(1).Headers(1).InlineShapes.AddPicture sFileName, False,
> > true
> > With docActive.PageSetup
> >    .DifferentFirstPageHeaderFooter = False 'Set this to false will put 
> > text
> > on first page, else will not.
> > End With
> > 
> 
> 
>
date: Wed, 12 Mar 2008 13:18:00 -0700   author:   Brandon M. Hunter

Re: Adding an image to headers dynamically using VBA Word   
Could you provide some sample code on how to do this?

"Doug Robbins - Word MVP" wrote:

> Why don't you start with a template that already contains the image? (and 
> use code to delete it if there are some occasions when you do not want it.)
> 
> -- 
> Hope this helps.
> 
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
> 
> Doug Robbins - Word MVP
> 
> "Brandon M. Hunter" <Brandon M. Hunter@discussions.microsoft.com> wrote in 
> message news:3787A7AE-C934-4CD5-80F3-747551387193@microsoft.com...
> > Hi,
> > I've been having the hardest time adding an image to a header in word 
> > using
> > VBA Word. Below is the following code that I'm using to add an image to 
> > the
> > header. In full I want to have the ability to add to the header and footer
> > for each page.
> >
> >
> > docActive.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> > docActive.Sections(1).Headers(1).InlineShapes.AddPicture sFileName, False,
> > true
> > With docActive.PageSetup
> >    .DifferentFirstPageHeaderFooter = False 'Set this to false will put 
> > text
> > on first page, else will not.
> > End With
> > 
> 
> 
>
date: Wed, 12 Mar 2008 13:20:02 -0700   author:   Brandon M. Hunter

Re: Adding an image to headers dynamically using VBA Word   
To add a picture to the .Range of the primary header of the first section in 
the document, you would use:

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.InlineShapes.AddPicture 
FileName:="Path\Filename"

As you probably want other things in the header, it is usually best to 
insert a table in the header and then insert the picture into a particular 
cell of that table

 ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,1).Range.InlineShapes.AddPicture Filename:="path\filename"--Hope this helps.Please reply to the newsgroup unless you wish to avail yourself of myservices on a paid consulting basis.Doug Robbins - Word MVP"Brandon M. Hunter"  wrote inmessage news:523FFE3F-F65E-4931-BEA5-37EB6CD17E81@microsoft.com...> I've tried and it doesn't work when it comes to adding the image to the> header or footer. That would be nice, but all the code that I've tried,> fails. Do you have any sample code that I take a look at, or maybe help me> out with the code I posted. I've been at this for about 2 days. I can add> text to both the header and footer, but I can't add images.>> "Doug Robbins - Word MVP" wrote:>>> Why don't you start with a template that already contains the image? (and>> use code to delete it if there are some occasions when you do not wantit.)>>>> -->> Hope this helps.>>>> Please reply to the newsgroup unless you wish to avail yourself of my>> services on a paid consulting basis.>>>> Doug Robbins - Word MVP>>>> "Brandon M. Hunter" <Brandon M. Hunter@discussions.microsoft.com> wrotein>> message news:3787A7AE-C934-4CD5-80F3-747551387193@microsoft.com...>> > Hi,>> > I've been having the hardest time adding an image to a header in word>> > using>> > VBA Word. Below is the following code that I'm using to add an image to>> > the>> > header. In full I want to have the ability to add to the header andfooter>> > for each page.>> >>> >>> > docActive.ActiveWindow.ActivePane.View.SeekView =wdSeekCurrentPageHeader>> > docActive.Sections(1).Headers(1).InlineShapes.AddPicture sFileName,False,>> > true>> > With docActive.PageSetup>> >    .DifferentFirstPageHeaderFooter = False 'Set this to false will put>> > text>> > on first page, else will not.>> > End With>> >>>>>>>
date: Thu, 13 Mar 2008 08:50:22 +1000   author:   Doug Robbins - Word MVP

Re: Adding an image to headers dynamically using VBA Word   
Below is the code that I'm using now, s is the picture name that already 
exists on the document. The image is not inserted into the header. I tried 
your code and it didn't work. Do see why this wouldn't work? Thank you for 
the code. Please help, this is killing me.
Thanks in advance
Sub AddHeader(s)
    Dim docTemplate
    Dim hdr1
    Set docActive = objWord.ActiveDocument
    docActive.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    docActive.Shapes(s).Select
    Set hdr1 = docActive.Sections(1).Headers(1)
    hdr1.Range.Copy
    hdr1.Range.Paste
    With docActive.PageSetup
            .DifferentFirstPageHeaderFooter = False 
    End With
End Sub

"Doug Robbins - Word MVP" wrote:

> To add a picture to the .Range of the primary header of the first section in 
> the document, you would use:
> 
> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.InlineShapes.AddPicture 
> FileName:="Path\Filename"
> 
> As you probably want other things in the header, it is usually best to 
> insert a table in the header and then insert the picture into a particular 
> cell of that table
> 
>  ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,1).Range.InlineShapes.AddPicture Filename:="path\filename"--Hope this helps.Please reply to the newsgroup unless you wish to avail yourself of myservices on a paid consulting basis.Doug Robbins - Word MVP"Brandon M. Hunter"  wrote inmessage news:523FFE3F-F65E-4931-BEA5-37EB6CD17E81@microsoft.com...> I've tried and it doesn't work when it comes to adding the image to the> header or footer. That would be nice, but all the code that I've tried,> fails. Do you have any sample code that I take a look at, or maybe help me> out with the code I posted. I've been at this for about 2 days. I can add> text to both the header and footer, but I can't add images.>> "Doug Robbins - Word MVP" wrote:>>> Why don't you start with a template that already contains the image? (and>> use code to delete it if there are some occasions when you do not wantit.)>>>> -->> Hope this 
helps.>>>> Please reply to the newsgroup unless you wish to avail yourself of my>> services on a paid consulting basis.>>>> Doug Robbins - Word MVP>>>> "Brandon M. Hunter" <Brandon M. Hunter@discussions.microsoft.com> wrotein>> message news:3787A7AE-C934-4CD5-80F3-747551387193@microsoft.com...>> > Hi,>> > I've been having the hardest time adding an image to a header in word>> > using>> > VBA Word. Below is the following code that I'm using to add an image to>> > the>> > header. In full I want to have the ability to add to the header andfooter>> > for each page.>> >>> >>> > docActive.ActiveWindow.ActivePane.View.SeekView =wdSeekCurrentPageHeader>> > docActive.Sections(1).Headers(1).InlineShapes.AddPicture sFileName,False,>> > true>> > With docActive.PageSetup>> >    .DifferentFirstPageHeaderFooter = False 'Set this to false will put>> > text>> > on first page, else will not.>> > End With>> >>>>>>>
> 
>
date: Wed, 12 Mar 2008 16:05:01 -0700   author:   Brandon M. Hunter

Re: Adding an image to headers dynamically using VBA Word   
You are not copying the picture.  You are copying the range of the header 
and pasting it into itself.

It might work if you had:

docActive.Shapes(s).Select
Selection.Copy  'maybe Selection.CopyAsPicture
Set hdr1 = docActive.Sections(1).Headers(1)
hdr1.Range.Paste

You don't need to open the header pane if you are operating on the ..Range 
of the header

Hence,

docActive.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

should not be necessary.
-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Brandon M. Hunter"  wrote in 
message news:A42ACCA1-5A27-4C20-99B2-9BF8DA4197A9@microsoft.com...
> Below is the code that I'm using now, s is the picture name that already
> exists on the document. The image is not inserted into the header. I tried
> your code and it didn't work. Do see why this wouldn't work? Thank you for
> the code. Please help, this is killing me.
> Thanks in advance
> Sub AddHeader(s)
>    Dim docTemplate
>    Dim hdr1
>    Set docActive = objWord.ActiveDocument
>    docActive.ActiveWindow.ActivePane.View.SeekView = 
> wdSeekCurrentPageHeader
>    docActive.Shapes(s).Select
>    Set hdr1 = docActive.Sections(1).Headers(1)
>    hdr1.Range.Copy
>    hdr1.Range.Paste
>    With docActive.PageSetup
>            .DifferentFirstPageHeaderFooter = False
>    End With
> End Sub
>
> "Doug Robbins - Word MVP" wrote:
>
>> To add a picture to the .Range of the primary header of the first section 
>> in
>> the document, you would use:
>>
>> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.InlineShapes.AddPicture
>> FileName:="Path\Filename"
>>
>> As you probably want other things in the header, it is usually best to
>> insert a table in the header and then insert the picture into a 
>> particular
>> cell of that table
>>
>> 
>> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,1).Range.InlineShapes.AddPicture 
>> Filename:="path\filename"--Hope this helps.Please reply to the newsgroup 
>> unless you wish to avail yourself of myservices on a paid consulting 
>> basis.Doug Robbins - Word MVP"Brandon M. Hunter" 
>>  wrote inmessage 
>> news:523FFE3F-F65E-4931-BEA5-37EB6CD17E81@microsoft.com...> I've tried 
>> and it doesn't work when it comes to adding the image to the> header or 
>> footer. That would be nice, but all the code that I've tried,> fails. Do 
>> you have any sample code that I take a look at, or maybe help me> out 
>> with the code I posted. I've been at this for about 2 days. I can add> 
>> text to both the header and footer, but I can't add images.>> "Doug 
>> Robbins - Word MVP" wrote:>>> Why don't you start with a template that 
>> already contains the image? (and>> use code to delete it if there are 
>> some occasions when you do not wantit.)>>>> -->> Hope this
> helps.>>>> Please reply to the newsgroup unless you wish to avail yourself 
> of my>> services on a paid consulting basis.>>>> Doug Robbins - Word 
> MVP>>>> "Brandon M. Hunter" <Brandon M. Hunter@discussions.microsoft.com> 
> wrotein>> message 
> news:3787A7AE-C934-4CD5-80F3-747551387193@microsoft.com...>> > Hi,>> > 
> I've been having the hardest time adding an image to a header in word>> > 
> using>> > VBA Word. Below is the following code that I'm using to add an 
> image to>> > the>> > header. In full I want to have the ability to add to 
> the header andfooter>> > for each page.>> >>> >>> > 
> docActive.ActiveWindow.ActivePane.View.SeekView =wdSeekCurrentPageHeader>> 
>  > docActive.Sections(1).Headers(1).InlineShapes.AddPicture 
> sFileName,False,>> > true>> > With docActive.PageSetup>> > 
> .DifferentFirstPageHeaderFooter = False 'Set this to false will put>> > 
> text>> > on first page, else will not.>> > End With>> >>>>>>>
>>
>>
date: Thu, 13 Mar 2008 10:46:12 +1000   author:   Doug Robbins - Word MVP

Re: Adding an image to headers dynamically using VBA Word   
Thank you so much much. The Code works, but I was wondering, the code to add 
the same image to the footer, just overlap the header image. Here's my code. 
I call the AddHeader First, and then AddFooter second. Is there any reason 
why I don't get the footer image in the actual footer of my document?
Thanks, 
P.S. Where do I sign up for the newsgroup?
Sub AddHeader(s)
    Dim docTemplate
    Dim hdr1
    Set docActive = objWord.ActiveDocument'.Shapes(s).Select
    docActive.Shapes(s).Select
    objWord.Selection.Copy
    Set hdr1 = docActive.Sections(1).Headers(1)
    hdr1.Range.Paste
    With docActive.PageSetup
           .DifferentFirstPageHeaderFooter = False 
    End With
End Sub
Sub AddFooter(s)
    Dim fdr1
    Set docActive = objWord.ActiveDocument
    docActive.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    docActive.Shapes(s).Select
    objWord.Selection.Copy
    Set fdr1 = docActive.Sections(1).Footers(1)
    fdr1.Range.Paste
    With docActive.PageSetup
           .DifferentFirstPageHeaderFooter = False 
    End With
End sub

"Doug Robbins - Word MVP" wrote:

> You are not copying the picture.  You are copying the range of the header 
> and pasting it into itself.
> 
> It might work if you had:
> 
> docActive.Shapes(s).Select
> Selection.Copy  'maybe Selection.CopyAsPicture
> Set hdr1 = docActive.Sections(1).Headers(1)
> hdr1.Range.Paste
> 
> You don't need to open the header pane if you are operating on the ..Range 
> of the header
> 
> Hence,
> 
> docActive.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> 
> should not be necessary.
> -- 
> Hope this helps.
> 
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
> 
> Doug Robbins - Word MVP
> 
> "Brandon M. Hunter"  wrote in 
> message news:A42ACCA1-5A27-4C20-99B2-9BF8DA4197A9@microsoft.com...
> > Below is the code that I'm using now, s is the picture name that already
> > exists on the document. The image is not inserted into the header. I tried
> > your code and it didn't work. Do see why this wouldn't work? Thank you for
> > the code. Please help, this is killing me.
> > Thanks in advance
> > Sub AddHeader(s)
> >    Dim docTemplate
> >    Dim hdr1
> >    Set docActive = objWord.ActiveDocument
> >    docActive.ActiveWindow.ActivePane.View.SeekView = 
> > wdSeekCurrentPageHeader
> >    docActive.Shapes(s).Select
> >    Set hdr1 = docActive.Sections(1).Headers(1)
> >    hdr1.Range.Copy
> >    hdr1.Range.Paste
> >    With docActive.PageSetup
> >            .DifferentFirstPageHeaderFooter = False
> >    End With
> > End Sub
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >> To add a picture to the .Range of the primary header of the first section 
> >> in
> >> the document, you would use:
> >>
> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.InlineShapes.AddPicture
> >> FileName:="Path\Filename"
> >>
> >> As you probably want other things in the header, it is usually best to
> >> insert a table in the header and then insert the picture into a 
> >> particular
> >> cell of that table
> >>
> >> 
> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,1).Range.InlineShapes.AddPicture 
> >> Filename:="path\filename"--Hope this helps.Please reply to the newsgroup 
> >> unless you wish to avail yourself of myservices on a paid consulting 
> >> basis.Doug Robbins - Word MVP"Brandon M. Hunter" 
> >>  wrote inmessage 
> >> news:523FFE3F-F65E-4931-BEA5-37EB6CD17E81@microsoft.com...> I've tried 
> >> and it doesn't work when it comes to adding the image to the> header or 
> >> footer. That would be nice, but all the code that I've tried,> fails. Do 
> >> you have any sample code that I take a look at, or maybe help me> out 
> >> with the code I posted. I've been at this for about 2 days. I can add> 
> >> text to both the header and footer, but I can't add images.>> "Doug 
> >> Robbins - Word MVP" wrote:>>> Why don't you start with a template that 
> >> already contains the image? (and>> use code to delete it if there are 
> >> some occasions when you do not wantit.)>>>> -->> Hope this
> > helps.>>>> Please reply to the newsgroup unless you wish to avail yourself 
> > of my>> services on a paid consulting basis.>>>> Doug Robbins - Word 
> > MVP>>>> "Brandon M. Hunter" <Brandon M. Hunter@discussions.microsoft.com> 
> > wrotein>> message 
> > news:3787A7AE-C934-4CD5-80F3-747551387193@microsoft.com...>> > Hi,>> > 
> > I've been having the hardest time adding an image to a header in word>> > 
> > using>> > VBA Word. Below is the following code that I'm using to add an 
> > image to>> > the>> > header. In full I want to have the ability to add to 
> > the header andfooter>> > for each page.>> >>> >>> > 
> > docActive.ActiveWindow.ActivePane.View.SeekView =wdSeekCurrentPageHeader>> 
> >  > docActive.Sections(1).Headers(1).InlineShapes.AddPicture 
> > sFileName,False,>> > true>> > With docActive.PageSetup>> > 
> > .DifferentFirstPageHeaderFooter = False 'Set this to false will put>> > 
> > text>> > on first page, else will not.>> > End With>> >>>>>>>
> >>
> >> 
> 
> 
>
date: Wed, 12 Mar 2008 18:07:01 -0700   author:   Brandon M. Hunter

Re: Adding an image to headers dynamically using VBA Word   
I think that you need to declare fdr as a Range

    Dim fdr1 As Range

then use

    Set fdr1 = docActive.Sections(1).Footers(1).Range
    fdr1.Paste



-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Brandon M. Hunter"  wrote in 
message news:BB163EFA-5091-4C6E-8687-9F1CB11BE131@microsoft.com...
> Thank you so much much. The Code works, but I was wondering, the code to 
> add
> the same image to the footer, just overlap the header image. Here's my 
> code.
> I call the AddHeader First, and then AddFooter second. Is there any reason
> why I don't get the footer image in the actual footer of my document?
> Thanks,
> P.S. Where do I sign up for the newsgroup?
> Sub AddHeader(s)
>    Dim docTemplate
>    Dim hdr1
>    Set docActive = objWord.ActiveDocument'.Shapes(s).Select
>    docActive.Shapes(s).Select
>    objWord.Selection.Copy
>    Set hdr1 = docActive.Sections(1).Headers(1)
>    hdr1.Range.Paste
>    With docActive.PageSetup
>           .DifferentFirstPageHeaderFooter = False
>    End With
> End Sub
> Sub AddFooter(s)
>    Dim fdr1
>    Set docActive = objWord.ActiveDocument
>    docActive.ActiveWindow.ActivePane.View.SeekView = 
> wdSeekCurrentPageFooter
>    docActive.Shapes(s).Select
>    objWord.Selection.Copy
>    Set fdr1 = docActive.Sections(1).Footers(1)
>    fdr1.Range.Paste
>    With docActive.PageSetup
>           .DifferentFirstPageHeaderFooter = False
>    End With
> End sub
>
> "Doug Robbins - Word MVP" wrote:
>
>> You are not copying the picture.  You are copying the range of the header
>> and pasting it into itself.
>>
>> It might work if you had:
>>
>> docActive.Shapes(s).Select
>> Selection.Copy  'maybe Selection.CopyAsPicture
>> Set hdr1 = docActive.Sections(1).Headers(1)
>> hdr1.Range.Paste
>>
>> You don't need to open the header pane if you are operating on the 
>> ..Range
>> of the header
>>
>> Hence,
>>
>> docActive.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
>>
>> should not be necessary.
>> -- 
>> Hope this helps.
>>
>> Please reply to the newsgroup unless you wish to avail yourself of my
>> services on a paid consulting basis.
>>
>> Doug Robbins - Word MVP
>>
>> "Brandon M. Hunter"  wrote in
>> message news:A42ACCA1-5A27-4C20-99B2-9BF8DA4197A9@microsoft.com...
>> > Below is the code that I'm using now, s is the picture name that 
>> > already
>> > exists on the document. The image is not inserted into the header. I 
>> > tried
>> > your code and it didn't work. Do see why this wouldn't work? Thank you 
>> > for
>> > the code. Please help, this is killing me.
>> > Thanks in advance
>> > Sub AddHeader(s)
>> >    Dim docTemplate
>> >    Dim hdr1
>> >    Set docActive = objWord.ActiveDocument
>> >    docActive.ActiveWindow.ActivePane.View.SeekView =
>> > wdSeekCurrentPageHeader
>> >    docActive.Shapes(s).Select
>> >    Set hdr1 = docActive.Sections(1).Headers(1)
>> >    hdr1.Range.Copy
>> >    hdr1.Range.Paste
>> >    With docActive.PageSetup
>> >            .DifferentFirstPageHeaderFooter = False
>> >    End With
>> > End Sub
>> >
>> > "Doug Robbins - Word MVP" wrote:
>> >
>> >> To add a picture to the .Range of the primary header of the first 
>> >> section
>> >> in
>> >> the document, you would use:
>> >>
>> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.InlineShapes.AddPicture
>> >> FileName:="Path\Filename"
>> >>
>> >> As you probably want other things in the header, it is usually best to
>> >> insert a table in the header and then insert the picture into a
>> >> particular
>> >> cell of that table
>> >>
>> >>
>> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,1).Range.InlineShapes.AddPicture
>> >> Filename:="path\filename"--Hope this helps.Please reply to the 
>> >> newsgroup
>> >> unless you wish to avail yourself of myservices on a paid consulting
>> >> basis.Doug Robbins - Word MVP"Brandon M. Hunter"
>> >>  wrote inmessage
>> >> news:523FFE3F-F65E-4931-BEA5-37EB6CD17E81@microsoft.com...> I've tried
>> >> and it doesn't work when it comes to adding the image to the> header 
>> >> or
>> >> footer. That would be nice, but all the code that I've tried,> fails. 
>> >> Do
>> >> you have any sample code that I take a look at, or maybe help me> out
>> >> with the code I posted. I've been at this for about 2 days. I can add>
>> >> text to both the header and footer, but I can't add images.>> "Doug
>> >> Robbins - Word MVP" wrote:>>> Why don't you start with a template that
>> >> already contains the image? (and>> use code to delete it if there are
>> >> some occasions when you do not wantit.)>>>> -->> Hope this
>> > helps.>>>> Please reply to the newsgroup unless you wish to avail 
>> > yourself
>> > of my>> services on a paid consulting basis.>>>> Doug Robbins - Word
>> > MVP>>>> "Brandon M. Hunter" <Brandon M. 
>> > Hunter@discussions.microsoft.com>
>> > wrotein>> message
>> > news:3787A7AE-C934-4CD5-80F3-747551387193@microsoft.com...>> > Hi,>> >
>> > I've been having the hardest time adding an image to a header in word>> 
>> >  >
>> > using>> > VBA Word. Below is the following code that I'm using to add 
>> > an
>> > image to>> > the>> > header. In full I want to have the ability to add 
>> > to
>> > the header andfooter>> > for each page.>> >>> >>> >
>> > docActive.ActiveWindow.ActivePane.View.SeekView 
>> > =wdSeekCurrentPageHeader>>
>> >  > docActive.Sections(1).Headers(1).InlineShapes.AddPicture
>> > sFileName,False,>> > true>> > With docActive.PageSetup>> >
>> > .DifferentFirstPageHeaderFooter = False 'Set this to false will put>> >
>> > text>> > on first page, else will not.>> > End With>> >>>>>>>
>> >>
>> >>
>>
>>
>>
date: Thu, 13 Mar 2008 15:31:56 +1000   author:   Doug Robbins - Word MVP

Re: Adding an image to headers dynamically using VBA Word   
It doesn't work. I don't think the Dim Frd1 As Range works for me. Also I've 
tried it without the first line and it stills overlaps the image. Is there 
another way?
"Doug Robbins - Word MVP" wrote:

> I think that you need to declare fdr as a Range
> 
>     Dim fdr1 As Range
> 
> then use
> 
>     Set fdr1 = docActive.Sections(1).Footers(1).Range
>     fdr1.Paste
> 
> 
> 
> -- 
> Hope this helps.
> 
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
> 
> Doug Robbins - Word MVP
> 
> "Brandon M. Hunter"  wrote in 
> message news:BB163EFA-5091-4C6E-8687-9F1CB11BE131@microsoft.com...
> > Thank you so much much. The Code works, but I was wondering, the code to 
> > add
> > the same image to the footer, just overlap the header image. Here's my 
> > code.
> > I call the AddHeader First, and then AddFooter second. Is there any reason
> > why I don't get the footer image in the actual footer of my document?
> > Thanks,
> > P.S. Where do I sign up for the newsgroup?
> > Sub AddHeader(s)
> >    Dim docTemplate
> >    Dim hdr1
> >    Set docActive = objWord.ActiveDocument'.Shapes(s).Select
> >    docActive.Shapes(s).Select
> >    objWord.Selection.Copy
> >    Set hdr1 = docActive.Sections(1).Headers(1)
> >    hdr1.Range.Paste
> >    With docActive.PageSetup
> >           .DifferentFirstPageHeaderFooter = False
> >    End With
> > End Sub
> > Sub AddFooter(s)
> >    Dim fdr1
> >    Set docActive = objWord.ActiveDocument
> >    docActive.ActiveWindow.ActivePane.View.SeekView = 
> > wdSeekCurrentPageFooter
> >    docActive.Shapes(s).Select
> >    objWord.Selection.Copy
> >    Set fdr1 = docActive.Sections(1).Footers(1)
> >    fdr1.Range.Paste
> >    With docActive.PageSetup
> >           .DifferentFirstPageHeaderFooter = False
> >    End With
> > End sub
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >> You are not copying the picture.  You are copying the range of the header
> >> and pasting it into itself.
> >>
> >> It might work if you had:
> >>
> >> docActive.Shapes(s).Select
> >> Selection.Copy  'maybe Selection.CopyAsPicture
> >> Set hdr1 = docActive.Sections(1).Headers(1)
> >> hdr1.Range.Paste
> >>
> >> You don't need to open the header pane if you are operating on the 
> >> ..Range
> >> of the header
> >>
> >> Hence,
> >>
> >> docActive.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> >>
> >> should not be necessary.
> >> -- 
> >> Hope this helps.
> >>
> >> Please reply to the newsgroup unless you wish to avail yourself of my
> >> services on a paid consulting basis.
> >>
> >> Doug Robbins - Word MVP
> >>
> >> "Brandon M. Hunter"  wrote in
> >> message news:A42ACCA1-5A27-4C20-99B2-9BF8DA4197A9@microsoft.com...
> >> > Below is the code that I'm using now, s is the picture name that 
> >> > already
> >> > exists on the document. The image is not inserted into the header. I 
> >> > tried
> >> > your code and it didn't work. Do see why this wouldn't work? Thank you 
> >> > for
> >> > the code. Please help, this is killing me.
> >> > Thanks in advance
> >> > Sub AddHeader(s)
> >> >    Dim docTemplate
> >> >    Dim hdr1
> >> >    Set docActive = objWord.ActiveDocument
> >> >    docActive.ActiveWindow.ActivePane.View.SeekView =
> >> > wdSeekCurrentPageHeader
> >> >    docActive.Shapes(s).Select
> >> >    Set hdr1 = docActive.Sections(1).Headers(1)
> >> >    hdr1.Range.Copy
> >> >    hdr1.Range.Paste
> >> >    With docActive.PageSetup
> >> >            .DifferentFirstPageHeaderFooter = False
> >> >    End With
> >> > End Sub
> >> >
> >> > "Doug Robbins - Word MVP" wrote:
> >> >
> >> >> To add a picture to the .Range of the primary header of the first 
> >> >> section
> >> >> in
> >> >> the document, you would use:
> >> >>
> >> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.InlineShapes.AddPicture
> >> >> FileName:="Path\Filename"
> >> >>
> >> >> As you probably want other things in the header, it is usually best to
> >> >> insert a table in the header and then insert the picture into a
> >> >> particular
> >> >> cell of that table
> >> >>
> >> >>
> >> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,1).Range.InlineShapes.AddPicture
> >> >> Filename:="path\filename"--Hope this helps.Please reply to the 
> >> >> newsgroup
> >> >> unless you wish to avail yourself of myservices on a paid consulting
> >> >> basis.Doug Robbins - Word MVP"Brandon M. Hunter"
> >> >>  wrote inmessage
> >> >> news:523FFE3F-F65E-4931-BEA5-37EB6CD17E81@microsoft.com...> I've tried
> >> >> and it doesn't work when it comes to adding the image to the> header 
> >> >> or
> >> >> footer. That would be nice, but all the code that I've tried,> fails. 
> >> >> Do
> >> >> you have any sample code that I take a look at, or maybe help me> out
> >> >> with the code I posted. I've been at this for about 2 days. I can add>
> >> >> text to both the header and footer, but I can't add images.>> "Doug
> >> >> Robbins - Word MVP" wrote:>>> Why don't you start with a template that
> >> >> already contains the image? (and>> use code to delete it if there are
> >> >> some occasions when you do not wantit.)>>>> -->> Hope this
> >> > helps.>>>> Please reply to the newsgroup unless you wish to avail 
> >> > yourself
> >> > of my>> services on a paid consulting basis.>>>> Doug Robbins - Word
> >> > MVP>>>> "Brandon M. Hunter" <Brandon M. 
> >> > Hunter@discussions.microsoft.com>
> >> > wrotein>> message
> >> > news:3787A7AE-C934-4CD5-80F3-747551387193@microsoft.com...>> > Hi,>> >
> >> > I've been having the hardest time adding an image to a header in word>> 
> >> >  >
> >> > using>> > VBA Word. Below is the following code that I'm using to add 
> >> > an
> >> > image to>> > the>> > header. In full I want to have the ability to add 
> >> > to
> >> > the header andfooter>> > for each page.>> >>> >>> >
> >> > docActive.ActiveWindow.ActivePane.View.SeekView 
> >> > =wdSeekCurrentPageHeader>>
> >> >  > docActive.Sections(1).Headers(1).InlineShapes.AddPicture
> >> > sFileName,False,>> > true>> > With docActive.PageSetup>> >
> >> > .DifferentFirstPageHeaderFooter = False 'Set this to false will put>> >
> >> > text>> > on first page, else will not.>> > End With>> >>>>>>>
> >> >>
> >> >>
> >>
> >>
> >> 
> 
> 
>
date: Thu, 13 Mar 2008 06:04:01 -0700   author:   Brandon M. Hunter

Re: Adding an image to headers dynamically using VBA Word   
If I select a picture in the body of the document and run a macro with the 
following code:

Dim fdr1 As Range
Selection.Copy
Set fdr1 = ActiveDocument.Sections(1).Footers(1).Range
fdr1.Paste

the picture is pasted into the footer.

And, if I run a macro with the following code

Dim fdr1 As Range
Selection.Copy
With ActiveDocument.Sections(1)
    Set fdr1 = .Footers(1).Range
    fdr1.Paste
    Set fdr1 = .Headers(1).Range
    fdr1.Paste
End With
End Sub

The picture is pasted into both the header and the footer.

As I have mentioned before, you do not need to open the header/footer pane
-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Brandon M. Hunter"  wrote in 
message news:E13036CD-0297-4D66-B011-C08866D083E0@microsoft.com...
>
> It doesn't work. I don't think the Dim Frd1 As Range works for me. Also 
> I've
> tried it without the first line and it stills overlaps the image. Is there
> another way?
> "Doug Robbins - Word MVP" wrote:
>
>> I think that you need to declare fdr as a Range
>>
>>     Dim fdr1 As Range
>>
>> then use
>>
>>     Set fdr1 = docActive.Sections(1).Footers(1).Range
>>     fdr1.Paste
>>
>>
>>
>> -- 
>> Hope this helps.
>>
>> Please reply to the newsgroup unless you wish to avail yourself of my
>> services on a paid consulting basis.
>>
>> Doug Robbins - Word MVP
>>
>> "Brandon M. Hunter"  wrote in
>> message news:BB163EFA-5091-4C6E-8687-9F1CB11BE131@microsoft.com...
>> > Thank you so much much. The Code works, but I was wondering, the code 
>> > to
>> > add
>> > the same image to the footer, just overlap the header image. Here's my
>> > code.
>> > I call the AddHeader First, and then AddFooter second. Is there any 
>> > reason
>> > why I don't get the footer image in the actual footer of my document?
>> > Thanks,
>> > P.S. Where do I sign up for the newsgroup?
>> > Sub AddHeader(s)
>> >    Dim docTemplate
>> >    Dim hdr1
>> >    Set docActive = objWord.ActiveDocument'.Shapes(s).Select
>> >    docActive.Shapes(s).Select
>> >    objWord.Selection.Copy
>> >    Set hdr1 = docActive.Sections(1).Headers(1)
>> >    hdr1.Range.Paste
>> >    With docActive.PageSetup
>> >           .DifferentFirstPageHeaderFooter = False
>> >    End With
>> > End Sub
>> > Sub AddFooter(s)
>> >    Dim fdr1
>> >    Set docActive = objWord.ActiveDocument
>> >    docActive.ActiveWindow.ActivePane.View.SeekView =
>> > wdSeekCurrentPageFooter
>> >    docActive.Shapes(s).Select
>> >    objWord.Selection.Copy
>> >    Set fdr1 = docActive.Sections(1).Footers(1)
>> >    fdr1.Range.Paste
>> >    With docActive.PageSetup
>> >           .DifferentFirstPageHeaderFooter = False
>> >    End With
>> > End sub
>> >
>> > "Doug Robbins - Word MVP" wrote:
>> >
>> >> You are not copying the picture.  You are copying the range of the 
>> >> header
>> >> and pasting it into itself.
>> >>
>> >> It might work if you had:
>> >>
>> >> docActive.Shapes(s).Select
>> >> Selection.Copy  'maybe Selection.CopyAsPicture
>> >> Set hdr1 = docActive.Sections(1).Headers(1)
>> >> hdr1.Range.Paste
>> >>
>> >> You don't need to open the header pane if you are operating on the
>> >> ..Range
>> >> of the header
>> >>
>> >> Hence,
>> >>
>> >> docActive.ActiveWindow.ActivePane.View.SeekView = 
>> >> wdSeekCurrentPageHeader
>> >>
>> >> should not be necessary.
>> >> -- 
>> >> Hope this helps.
>> >>
>> >> Please reply to the newsgroup unless you wish to avail yourself of my
>> >> services on a paid consulting basis.
>> >>
>> >> Doug Robbins - Word MVP
>> >>
>> >> "Brandon M. Hunter"  wrote 
>> >> in
>> >> message news:A42ACCA1-5A27-4C20-99B2-9BF8DA4197A9@microsoft.com...
>> >> > Below is the code that I'm using now, s is the picture name that
>> >> > already
>> >> > exists on the document. The image is not inserted into the header. I
>> >> > tried
>> >> > your code and it didn't work. Do see why this wouldn't work? Thank 
>> >> > you
>> >> > for
>> >> > the code. Please help, this is killing me.
>> >> > Thanks in advance
>> >> > Sub AddHeader(s)
>> >> >    Dim docTemplate
>> >> >    Dim hdr1
>> >> >    Set docActive = objWord.ActiveDocument
>> >> >    docActive.ActiveWindow.ActivePane.View.SeekView =
>> >> > wdSeekCurrentPageHeader
>> >> >    docActive.Shapes(s).Select
>> >> >    Set hdr1 = docActive.Sections(1).Headers(1)
>> >> >    hdr1.Range.Copy
>> >> >    hdr1.Range.Paste
>> >> >    With docActive.PageSetup
>> >> >            .DifferentFirstPageHeaderFooter = False
>> >> >    End With
>> >> > End Sub
>> >> >
>> >> > "Doug Robbins - Word MVP" wrote:
>> >> >
>> >> >> To add a picture to the .Range of the primary header of the first
>> >> >> section
>> >> >> in
>> >> >> the document, you would use:
>> >> >>
>> >> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.InlineShapes.AddPicture
>> >> >> FileName:="Path\Filename"
>> >> >>
>> >> >> As you probably want other things in the header, it is usually best 
>> >> >> to
>> >> >> insert a table in the header and then insert the picture into a
>> >> >> particular
>> >> >> cell of that table
>> >> >>
>> >> >>
>> >> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,1).Range.InlineShapes.AddPicture
>> >> >> Filename:="path\filename"--Hope this helps.Please reply to the
>> >> >> newsgroup
>> >> >> unless you wish to avail yourself of myservices on a paid 
>> >> >> consulting
>> >> >> basis.Doug Robbins - Word MVP"Brandon M. Hunter"
>> >> >>  wrote inmessage
>> >> >> news:523FFE3F-F65E-4931-BEA5-37EB6CD17E81@microsoft.com...> I've 
>> >> >> tried
>> >> >> and it doesn't work when it comes to adding the image to the> 
>> >> >> header
>> >> >> or
>> >> >> footer. That would be nice, but all the code that I've tried,> 
>> >> >> fails.
>> >> >> Do
>> >> >> you have any sample code that I take a look at, or maybe help me> 
>> >> >> out
>> >> >> with the code I posted. I've been at this for about 2 days. I can 
>> >> >> add>
>> >> >> text to both the header and footer, but I can't add images.>> "Doug
>> >> >> Robbins - Word MVP" wrote:>>> Why don't you start with a template 
>> >> >> that
>> >> >> already contains the image? (and>> use code to delete it if there 
>> >> >> are
>> >> >> some occasions when you do not wantit.)>>>> -->> Hope this
>> >> > helps.>>>> Please reply to the newsgroup unless you wish to avail
>> >> > yourself
>> >> > of my>> services on a paid consulting basis.>>>> Doug Robbins - Word
>> >> > MVP>>>> "Brandon M. Hunter" <Brandon M.
>> >> > Hunter@discussions.microsoft.com>
>> >> > wrotein>> message
>> >> > news:3787A7AE-C934-4CD5-80F3-747551387193@microsoft.com...>> > Hi,>> 
>> >> >  >
>> >> > I've been having the hardest time adding an image to a header in 
>> >> > word>>
>> >> >  >
>> >> > using>> > VBA Word. Below is the following code that I'm using to 
>> >> > add
>> >> > an
>> >> > image to>> > the>> > header. In full I want to have the ability to 
>> >> > add
>> >> > to
>> >> > the header andfooter>> > for each page.>> >>> >>> >
>> >> > docActive.ActiveWindow.ActivePane.View.SeekView
>> >> > =wdSeekCurrentPageHeader>>
>> >> >  > docActive.Sections(1).Headers(1).InlineShapes.AddPicture
>> >> > sFileName,False,>> > true>> > With docActive.PageSetup>> >
>> >> > .DifferentFirstPageHeaderFooter = False 'Set this to false will 
>> >> > put>> >
>> >> > text>> > on first page, else will not.>> > End With>> >>>>>>>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>>
date: Fri, 14 Mar 2008 05:58:23 +1000   author:   Doug Robbins - Word MVP

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us