Reply
 
Thread Tools Display Modes
  #1   Report Post  
Rick Tawney
 
Posts: n/a
Default Creating headers using macros

I'm using Microsoft Word 2002 SP3 on XP to try and use macros to create
different headers within a document with, the user is prompted with MsgBox
for input. There seems to be two problems. 1) When I use a macro to go to the
current header ir does not. It may go to the last or the next header. 2) The
curser location in the header can not be controlled with a macro. When
instructed to go to the top then move down two lines it does not.

Any help would be appreciated.
--
Rick Tawney
  #2   Report Post  
Jezebel
 
Posts: n/a
Default

The trick is to avoid the Selection object completely. Don't try to 'go' to
the header. Refer to the headers directly, eg

With Activedocument.Sections(3).Headers(wdHeaderFooterF irstPage)
.LinkToPrevious = false
.Range = "New header for first page of section 3"
End with




"Rick Tawney" wrote in message
...
I'm using Microsoft Word 2002 SP3 on XP to try and use macros to create
different headers within a document with, the user is prompted with MsgBox
for input. There seems to be two problems. 1) When I use a macro to go to

the
current header ir does not. It may go to the last or the next header. 2)

The
curser location in the header can not be controlled with a macro. When
instructed to go to the top then move down two lines it does not.

Any help would be appreciated.
--
Rick Tawney



  #3   Report Post  
Rick Tawney
 
Posts: n/a
Default

Thanks for the try Jezebel, I tried your suggestion but I couldnt get it to
work. Im not that savvy with VB so that no doubt is a obstacle. For further
clarification I want to create a section break and then go to this new
section, there could be any number of sections in the document, prompt for
user input to create the new header then return to the body of the document
until the next new section needs to be created. Or create new headers for the
next section as you go along in the document. If Im reading what you sent me
right it would work for section 3. I need to create new headers for each new
section.

"Rick Tawney" wrote:

I'm using Microsoft Word 2002 SP3 on XP to try and use macros to create
different headers within a document with, the user is prompted with MsgBox
for input. There seems to be two problems. 1) When I use a macro to go to the
current header ir does not. It may go to the last or the next header. 2) The
curser location in the header can not be controlled with a macro. When
instructed to go to the top then move down two lines it does not.

Any help would be appreciated.
--
Rick Tawney

  #4   Report Post  
Jezebel
 
Posts: n/a
Default

Section 3 was just for the example. You can use Document.Sections.Count to
find out how many sections there are in the document. You can use
Selection.Sections(1).Index to get the number of the first section
containing the current selection.

You could have a macro that inserts a section break at end of document, then
adds a new header to it, along these lines --

With ActiveDocument
.Sections.Add Start:=wdSectionNewPage
With .Sections(.Sections.Count).Headers(wdHeaderFooterF irstPage)
.LinkToPrevious = false
.Range = "New header for first page of new section"
End with
End with

Check Help for the arguments to the Sections.Add function and Headers()
collection.





"Rick Tawney" wrote in message
...
Thanks for the try Jezebel, I tried your suggestion but I couldn't get it

to
work. I'm not that savvy with VB so that no doubt is a obstacle. For

further
clarification I want to create a section break and then go to this new
section, there could be any number of sections in the document, prompt for
user input to create the new header then return to the body of the

document
until the next new section needs to be created. Or create new headers for

the
next section as you go along in the document. If I'm reading what you sent

me
right it would work for section 3. I need to create new headers for each

new
section.

"Rick Tawney" wrote:

I'm using Microsoft Word 2002 SP3 on XP to try and use macros to create
different headers within a document with, the user is prompted with

MsgBox
for input. There seems to be two problems. 1) When I use a macro to go

to the
current header ir does not. It may go to the last or the next header. 2)

The
curser location in the header can not be controlled with a macro. When
instructed to go to the top then move down two lines it does not.

Any help would be appreciated.
--
Rick Tawney



  #5   Report Post  
Rick Tawney
 
Posts: n/a
Default

I tried the last one with no sucess here is what I came up with. As you can
see the text from this macro is entered in the body and not the header of the
next section. help: thanks

With ActiveDocument
.Sections.Add Start:=wdSectionNewPage
With .Sections(.Sections.Count).Headers(wdHeaderFooterF irstPage)
.LinkToPrevious = False
.Range = "New header for first page of new section"
headervar = InputBox("1-Chapter 1 2-Chapter 2 3-Capter 3", "Header", 1)
Select Case headervar
Case "1"
Selection.TypeText Text:=" Chapter One "
Case "2"
Selection.TypeText Text:=" Chapter Two "
Case "3"
Selection.TypeText Text:=" Chapter Three "
End Select

End With
End With


"Jezebel" wrote:

Section 3 was just for the example. You can use Document.Sections.Count to
find out how many sections there are in the document. You can use
Selection.Sections(1).Index to get the number of the first section
containing the current selection.

You could have a macro that inserts a section break at end of document, then
adds a new header to it, along these lines --

With ActiveDocument
.Sections.Add Start:=wdSectionNewPage
With .Sections(.Sections.Count).Headers(wdHeaderFooterF irstPage)
.LinkToPrevious = false
.Range = "New header for first page of new section"
End with
End with

Check Help for the arguments to the Sections.Add function and Headers()
collection.





"Rick Tawney" wrote in message
...
Thanks for the try Jezebel, I tried your suggestion but I couldn't get it

to
work. I'm not that savvy with VB so that no doubt is a obstacle. For

further
clarification I want to create a section break and then go to this new
section, there could be any number of sections in the document, prompt for
user input to create the new header then return to the body of the

document
until the next new section needs to be created. Or create new headers for

the
next section as you go along in the document. If I'm reading what you sent

me
right it would work for section 3. I need to create new headers for each

new
section.

"Rick Tawney" wrote:

I'm using Microsoft Word 2002 SP3 on XP to try and use macros to create
different headers within a document with, the user is prompted with

MsgBox
for input. There seems to be two problems. 1) When I use a macro to go

to the
current header ir does not. It may go to the last or the next header. 2)

The
curser location in the header can not be controlled with a macro. When
instructed to go to the top then move down two lines it does not.

Any help would be appreciated.
--
Rick Tawney






  #6   Report Post  
Jezebel
 
Posts: n/a
Default

Writing macros by trial and error like this is the devil's own task. If you
want to learn to write macros, take the time to read Help on it.

Your text is being entered in the body because that's where the selection
is. You'll either need to select the header, or -- better -- don't use the
Selection object in macros if you can avoid it -- and you nearly always can.

1. The Range statement is where you insert the text

..Range = "Chapter One" etc

2. Change wdHeaderFooterFirstPage if you don't have a different first page
header for each section.





"Rick Tawney" wrote in message
...
I tried the last one with no sucess here is what I came up with. As you

can
see the text from this macro is entered in the body and not the header of

the
next section. help: thanks

With ActiveDocument
.Sections.Add Start:=wdSectionNewPage
With .Sections(.Sections.Count).Headers(wdHeaderFooterF irstPage)
.LinkToPrevious = False
.Range = "New header for first page of new section"
headervar = InputBox("1-Chapter 1 2-Chapter 2 3-Capter 3", "Header",

1)
Select Case headervar
Case "1"
Selection.TypeText Text:=" Chapter One "
Case "2"
Selection.TypeText Text:=" Chapter Two "
Case "3"
Selection.TypeText Text:=" Chapter Three "
End Select

End With
End With


"Jezebel" wrote:

Section 3 was just for the example. You can use Document.Sections.Count

to
find out how many sections there are in the document. You can use
Selection.Sections(1).Index to get the number of the first section
containing the current selection.

You could have a macro that inserts a section break at end of document,

then
adds a new header to it, along these lines --

With ActiveDocument
.Sections.Add Start:=wdSectionNewPage
With .Sections(.Sections.Count).Headers(wdHeaderFooterF irstPage)
.LinkToPrevious = false
.Range = "New header for first page of new section"
End with
End with

Check Help for the arguments to the Sections.Add function and Headers()
collection.





"Rick Tawney" wrote in message
...
Thanks for the try Jezebel, I tried your suggestion but I couldn't

get it
to
work. I'm not that savvy with VB so that no doubt is a obstacle. For

further
clarification I want to create a section break and then go to this new
section, there could be any number of sections in the document, prompt

for
user input to create the new header then return to the body of the

document
until the next new section needs to be created. Or create new headers

for
the
next section as you go along in the document. If I'm reading what you

sent
me
right it would work for section 3. I need to create new headers for

each
new
section.

"Rick Tawney" wrote:

I'm using Microsoft Word 2002 SP3 on XP to try and use macros to

create
different headers within a document with, the user is prompted with

MsgBox
for input. There seems to be two problems. 1) When I use a macro to

go
to the
current header ir does not. It may go to the last or the next

header. 2)
The
curser location in the header can not be controlled with a macro.

When
instructed to go to the top then move down two lines it does not.

Any help would be appreciated.
--
Rick Tawney






Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Macros in 2003 multiple but connected problems? V-ger Microsoft Word Help 8 January 18th 05 09:42 PM
word xp crashes after macros are recorded kharris0405 Microsoft Word Help 3 January 11th 05 10:50 PM
Using Mail Merge for Creating a Document of Biographies... Sam Clarke Microsoft Word Help 1 January 4th 05 04:28 PM
Updating Cross References in Headers Darrell Microsoft Word Help 0 December 10th 04 02:15 AM
Macros in Normal.dot BenJ Microsoft Word Help 3 November 26th 04 11:08 AM


All times are GMT +1. The time now is 03:03 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"