Master Document - Further Question

D

Derek Hart

When a new document is opened in Word, there is no option on a header/footer
to choose "Same As Previous" because there is no previous section. But when
the document comes into a master document, the Same As Previous option is
there by default. And this only happens if there is no header/footer in the
document. Remember, if I simply add a space to the header/footer, the
master document knows that this document has its own header/footer, and to
not bring over the previous header/footer. I have to find a way to automate
this process. When I add document to the master document:



DocMaster.Range.Subdocuments.AddFromFile
Name:=DocumentFile



I then need to go to the top of THAT document and determine if there is a
header/footer. If not, I need to add a space and make sure the option "Same
as Previous" is turned off. Let me know if you have any code samples to do
this, especially going to the top of a specific document within a master
document.



Derek Hart
 
C

Cindy M -WordMVP-

Hi Derek,

Assuming you're adding the new subdoc at the end of the Master doc, then you
should probably be able to identify the header/footer you need by determinig
the section. Headers and footers are part of a section object. I'd try
something like this

Dim subdoc as Word.SubDocument
Set subdoc = DocMaster.Range.Subdocuments.AddFromFile DocumentFile
subdoc.Range.Sections(1).Headers(wdHeaderFooterPrimary).SameAsPrevious = False
Remember, if I simply add a space to the header/footer, the
master document knows that this document has its own header/footer, and to
not bring over the previous header/footer. I have to find a way to automate
this process. When I add document to the master document:



DocMaster.Range.Subdocuments.AddFromFile
Name:=DocumentFile



I then need to go to the top of THAT document and determine if there is a
header/footer. If not, I need to add a space and make sure the option "Same
as Previous" is turned off. Let me know if you have any code samples to do
this, especially going to the top of a specific document within a master
document.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
D

Derek Hart

(1) I believe I should use LinkToPrevious, because SameAsPrevious was not
available. Is that correct?

(2) When I use this command, I get "Command Not Available" - probably this
happens because there is no header in the document to begin with? How could
I handle this situation? Create a header somehow with a blank space, and
then apply the code? Please let me know.

(3) You suggested using wdHeaderFooterPrimary, but what about
wdHeaderFooterFirstPage. Don't I need to use both to cover both
possibilities?

Thank You!

Derek Hart
 
C

Cindy M -WordMVP-

Hi Derek,
(1) I believe I should use LinkToPrevious, because SameAsPrevious was not
available. Is that correct?
Correct; "Same as Previous" is on the toolbar button said:
(2) When I use this command, I get "Command Not Available" - probably this
happens because there is no header in the document to begin with? How could
I handle this situation? Create a header somehow with a blank space, and
then apply the code? Please let me know.
That could be the case, or it could be because you're in the first section (no
"previous" is not available). For the former, try the .Exists property; for
the latter, check that you're not in Sections(1) (the .Information property)
Note: as far as I know, "primary" is *always* available, so it's more likely
you're in the first section.
(3) You suggested using wdHeaderFooterPrimary, but what about
wdHeaderFooterFirstPage. Don't I need to use both to cover both
possibilities?
Certainly, if that's relevant to your project :) There could also be EvenPage
(if "Different Odd/Even" is activate). Here, again, you could use .Exists.
(Note: there is a common, and understandable, misconception about what .Exists
does. It does NOT tell you whether there's any text in a header/footer; it's
an indication whether this type of header/footer is enabled in the document.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
D

Derek Hart

You had stated the following:

"Certainly, if that's relevant to your project :) There could also be
EvenPage
(if "Different Odd/Even" is activate). Here, again, you could use .Exists.
(Note: there is a common, and understandable, misconception about what
..Exists
does. It does NOT tell you whether there's any text in a header/footer; it's
an indication whether this type of header/footer is enabled in the
document."

I am applying code after the subdocument has been inserted into the Master
Document. At that time, if there is no header, I need to add a header, and
then set LinkToPrevious = False. Can you give me an example of code that
could add a header with just a space, or maybe just a paragraph mark, so one
does exist. I was playing with the range object and trying to create a
header, but could not get it working.

Thanks so much!

Derek
 
C

Cindy M -WordMVP-

Hi Derek,
I am applying code after the subdocument has been inserted into the Master
Document. At that time, if there is no header, I need to add a header, and
then set LinkToPrevious = False. Can you give me an example of code that
could add a header with just a space, or maybe just a paragraph mark, so one
does exist. I was playing with the range object and trying to create a
header, but could not get it working.
Something like this works for me

Dim subdoc As Word.Subdocument
Dim rng As Word.Range

Set subdoc = Selection.Range.Subdocuments.AddFromFile(Name:="test
doc.doc", _
ConfirmConversions:=True, ReadOnly:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="")
Set rng = subdoc.Range
rng.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = " "


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top