Help with handling a run-time error in a macro 
Author Message
 Help with handling a run-time error in a macro

Hi there,

I want to change text in a header of one
of sections of a file with the other
sections not affected. I wrote a macro for
the job with the first steps of dislinking
the header of the current section from the
previous section if any and dislinking the
header of the next section from the current
section if any. However, there is a
possibility that there is no next section
after the current section in which I plan
to change text. In that case, the macro goes
to a run-time error even if I have some error
correction in it. OK, here is main part of
the macro (more explantations after the macro).

---------
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.LinkToPrevious = True Then
Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
LinkToPrevious
ActiveWindow.ActivePane.View.NextHeaderFooter
Else
ActiveWindow.ActivePane.View.NextHeaderFooter
End If
On Error GoTo ProcedureA
If Selection.HeaderFooter.LinkToPrevious = True Then
Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
LinkToPrevious
ActiveWindow.ActivePane.View.PreviousHeaderFooter
Else
ActiveWindow.ActivePane.View.PreviousHeaderFooter
End If
GoTo ProcedureB
---------

In the case that no next secdtion exists,
the macro didn't go to procedureA, it always
gave the run-time error 4605 with debug
highlighting the line before or after else
of the first if statement.

ActiveWindow.ActivePane.View.NextHeaderFooter

Thank you very much for your help in solving
the problem.

Tony Lee

Sent via Deja.com
http://www.*-*-*.com/



Wed, 30 Jul 2003 00:39:02 GMT  
 Help with handling a run-time error in a macro
You're getting the error because you're attempting to access the next header
*before* you execute the On Error statement.

You might want to try using the HeadersFooters collection and looping
through that instead.

George



Quote:
> Hi there,

> I want to change text in a header of one
> of sections of a file with the other
> sections not affected. I wrote a macro for
> the job with the first steps of dislinking
> the header of the current section from the
> previous section if any and dislinking the
> header of the next section from the current
> section if any. However, there is a
> possibility that there is no next section
> after the current section in which I plan
> to change text. In that case, the macro goes
> to a run-time error even if I have some error
> correction in it. OK, here is main part of
> the macro (more explantations after the macro).

> ---------
> ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> If Selection.HeaderFooter.LinkToPrevious = True Then
> Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
> LinkToPrevious
> ActiveWindow.ActivePane.View.NextHeaderFooter
> Else
> ActiveWindow.ActivePane.View.NextHeaderFooter
> End If
> On Error GoTo ProcedureA
> If Selection.HeaderFooter.LinkToPrevious = True Then
> Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
> LinkToPrevious
> ActiveWindow.ActivePane.View.PreviousHeaderFooter
> Else
> ActiveWindow.ActivePane.View.PreviousHeaderFooter
> End If
> GoTo ProcedureB
> ---------

> In the case that no next secdtion exists,
> the macro didn't go to procedureA, it always
> gave the run-time error 4605 with debug
> highlighting the line before or after else
> of the first if statement.

> ActiveWindow.ActivePane.View.NextHeaderFooter

> Thank you very much for your help in solving
> the problem.

> Tony Lee

> Sent via Deja.com
> http://www.deja.com/



Wed, 30 Jul 2003 02:19:01 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Run-time error handling

2. Problem with Run-Time Error Handling

3. VBScript, type library, CTRL-BREAK and run-time error handling

4. Urgent: Handling run-time errors in COM components

5. Urgent: Handling run-time errors in COM components

6. Run-time error on macro

7. Microsoft Visual C++ Run time library Run time error R6025

8. Microsoft Visual C++ Run time library Run time error R6025

9. HELP : Error 91 : Run-Time Error 91 Object Variable or With

10. Macro runs three times if run through toolbar

11. HELP "Run-time error 432" HELP

12. Run-time error '-2147417846 (8001010a)': Automation error (error 440)

 

 
Powered by phpBB® Forum Software