Command Not Available error

B

Berlie

I have some macro code that in part created a new section then unlinks
the section's footers from the previous section.

I have one person who is using it that is getting a Command Not
Available error message.

The section of code that is giving the error is below with the line
highlighted when debugged noted.

Dim sCurSection As String
sCurSection = Selection.Information(wdActiveEndSectionNumber)
ActiveDocument.Range(Start:=Selection.Start,
End:=ActiveDocument.Content.End).PageSetup.VerticalAlignment =
wdAlignVerticalTop
With ActiveDocument.Sections(sCurSection)
With .Footers(wdHeaderFooterFirstPage)
.LinkToPrevious = False
End With
With .Footers(wdHeaderFooterEvenPages)
.LinkToPrevious = False <---- this line is giving the
error
End With
With .Footers(wdHeaderFooterPrimary)
.LinkToPrevious = False
End With



The person with the error is using Microsoft Word 2003 on a Windows XP
machine. I also use Word 2003 on an Win XP machine and don't get the
error.

Any ideas?
 
J

Jean-Guy Marcil

Berlie was telling us:
Berlie nous racontait que :
I have some macro code that in part created a new section then unlinks
the section's footers from the previous section.

I have one person who is using it that is getting a Command Not
Available error message.

The section of code that is giving the error is below with the line
highlighted when debugged noted.

Dim sCurSection As String
sCurSection = Selection.Information(wdActiveEndSectionNumber)
ActiveDocument.Range(Start:=Selection.Start,
End:=ActiveDocument.Content.End).PageSetup.VerticalAlignment =
wdAlignVerticalTop
With ActiveDocument.Sections(sCurSection)
With .Footers(wdHeaderFooterFirstPage)
.LinkToPrevious = False
End With
With .Footers(wdHeaderFooterEvenPages)
.LinkToPrevious = False <---- this line is giving the
error
End With
With .Footers(wdHeaderFooterPrimary)
.LinkToPrevious = False
End With



The person with the error is using Microsoft Word 2003 on a Windows XP
machine. I also use Word 2003 on an Win XP machine and don't get the
error.

Any ideas?

Make sure that this person's working document is identical to yours when
you compare things.

I often (after hours of frustrating bug hunting) find that users try to use
code in a fashion that does not make sense.
In your case, what if this person is using the code from the first section
in the document? There is nothing to link to before...

If this turns out to be the reason, modify your code to add "idiot proof"
messages, like "You cannot unlink to the previous section when you are in
the first section..."
(I know it is tempting to add "... idiot" or some other expletive, but I
find it is better not to, especially if you want repeat customers!)

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
B

Berlie

Thanks for your reply. I have walked the person through what they were
doing step by step on the phone and duplicated it on my computer. She
got the error and I did not. I haven't figured it out yet but she
tried it on another computer on her end and it is working for her on
that machine. /shrug
 
B

Berlie

The user is still seeing this erro on her work machine but not her
home one. I have changed the code to the following:

Selection.InsertBreak Type:=wdSectionBreakOddPage
ActiveDocument.Range(Start:=Selection.Start,
End:=ActiveDocument.Content.End).PageSetup.VerticalAlignment =
wdAlignVerticalTop

Dim pHeadFoot As Word.HeaderFooter

With Selection.Sections(1)
For Each pHeadFoot In .Footers
pHeadFoot.LinkToPrevious = False
Next
End With

She is getting the same error on the following line:

pHeadFoot.LinkToPrevious = False


She says that Word on her work machine is on a network while her home
computer is not. I am not sure how that would throw an error when
trying to unlink a footer from the previous however.

This really has me stumped. Anyone have any further ideas? My thanks
in advance.
 
J

Jean-Guy Marcil

Berlie was telling us:
Berlie nous racontait que :
The user is still seeing this erro on her work machine but not her
home one. I have changed the code to the following:

Selection.InsertBreak Type:=wdSectionBreakOddPage
ActiveDocument.Range(Start:=Selection.Start,
End:=ActiveDocument.Content.End).PageSetup.VerticalAlignment =
wdAlignVerticalTop

Dim pHeadFoot As Word.HeaderFooter

With Selection.Sections(1)
For Each pHeadFoot In .Footers
pHeadFoot.LinkToPrevious = False
Next
End With

She is getting the same error on the following line:

pHeadFoot.LinkToPrevious = False


She says that Word on her work machine is on a network while her home
computer is not. I am not sure how that would throw an error when
trying to unlink a footer from the previous however.

This really has me stumped. Anyone have any further ideas? My thanks
in advance.

I tried your code as is, and it worked as expected. But my computer is not
on a corporate network...
Anyway, as you mentioned, I do not think that the network is the cause.
There must be something else going on.

Are you sure she tried it with the same document? Send her a test document
and ask her to test it "as is" (she may have to send it to her house by
email) at both location.

Or, I see that you are using the Selection object.... this may lead to
unpredictable results, try using the Range object instead:

Dim rgeSection As Range
Dim lngSecCount As Long
Dim pHeadFoot As Word.HeaderFooter

Set rgeSection = Selection.Range

With rgeSection
lngSecCount = .Sections(1).Index
.InsertBreak wdSectionBreakOddPage
End With

With ActiveDocument
.Range(Start:=.Sections(lngSecCount + 1).Range.Start, _
End:=.Content.End).PageSetup.VerticalAlignment = wdAlignVerticalTop
With .Sections(lngSecCount + 1)
For Each pHeadFoot In .Footers
pHeadFoot.LinkToPrevious = False
Next
End With
End With



--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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