Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2005

Tip: Looking for answers? Try searching our database.

vba code for going into Word header

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kurt - 01 Aug 2005 19:20 GMT
I'm writing a macro that uses the following code, but at this point I get an
error, and my macro does not allow going into the header.

It works perfectly on a PC at my home, but not on the PC at my office.

The error I get is:  Object variable or WithBlock variable not set (Run time
error 91)

Any ideas?

   If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
       ActiveWindow.Panes(2).Close
   End If
   If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
       ActivePane.View.Type = wdOutlineView Then
       ActiveWindow.ActivePane.View.Type = wdPrintView
   End If
   ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
   Selection.MoveDown Unit:=wdLine, Count:=2
       Selection.PasteAndFormat (wdPasteDefault)

   ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

THANKS!

kurt
Jean-Guy Marcil - 02 Aug 2005 03:23 GMT
kurt was telling us:
kurt nous racontait que :

> I'm writing a macro that uses the following code, but at this point I
> get an error, and my macro does not allow going into the header.
[quoted text clipped - 18 lines]
>
>    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

Looks like you are using the macro recorder...

This is fine to get an idea, but you should refine it by hand, see

for more on this.
   http://word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm

Meanwhile, your macro could be simplified like this:
'_______________________________________
With Selection.Sections(1).Headers(wdHeaderFooterPrimary) _
   .Range.Paragraphs(3).Range

   .PasteAndFormat wdPasteDefault

End With
'_______________________________________

No Selection object and no need to "physically" go into the header.

You have to make sure the current header has at least three paragraphs and
you may want to change "wdHeaderFooterPrimary" to match your type of header.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

kurt - 02 Aug 2005 09:23 GMT
Bonjour Jean-Guy,

Merci pour votre aide!

Can you suggest a book or two for learning VBA in Word?

Merci mille fois.

Kurt
Signature

kurt

> kurt was telling us:
> kurt nous racontait que :
[quoted text clipped - 43 lines]
> You have to make sure the current header has at least three paragraphs and
> you may want to change "wdHeaderFooterPrimary" to match your type of header.
Jean-Guy Marcil - 02 Aug 2005 12:43 GMT
kurt was telling us:
kurt nous racontait que :

> Bonjour Jean-Guy,
>
> Merci pour votre aide!
>
> Can you suggest a book or two for learning VBA in Word?

I am not sure about particular books about VBA... but you can start by the
VBA section of the MVP site...
   http://word.mvps.org/faqs/MacrosVBA/index.htm

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.