table in header

G

Gavin0268

Hi
I have a macro attached to a template which creates a table in the header.
Recently, for some documents, but not all (and I can't see any pattern) I
occassionally get a 'Run-time errot 5941 - the requested member of the
collection does not exist'. It is stopping at the line indicated

If Left$(Currentfilename$, 1) = "~" Then

Select Case DocNew$

Case "FALSE"
Set rng = ActiveDocument.Range
rng.Font.Hidden = False

Set rng = ActiveDocument.Paragraphs(1).Range
rng.End = ActiveDocument.Paragraphs(2).Range.End (debug stops here)
rng.Font.Hidden = True

End Select

The macro was originally written for Word97. I think (but am not completely
certain) that the errors have started since we migrated to Office 2003.

If I press 'end' rather than 'debug', the header table is there, but without
borders.

Any suggestions welcome!

Thanks
 
G

Gavin0268

Thanks for the suggestion. I tried this:

If Left$(Currentfilename$, 1) = "~" Then

Select Case DocNew$

Case "FALSE"
Set Range = ActiveDocument.Range
Rng.Font.Hidden = False

Set Range = ActiveDocument.Paragraphs(1).Range
Rng.End = ActiveDocument.Paragraphs(2).Range.End
Rng.Font.Hidden = True

End Select

But it gave me a "compile error: invalid use of property". Am I changing the
wrong thing. I tried rng.setrange as well with the same effect
 
M

Marc Adams [marcmyword.com]

Gavin the syntax that I was referring to was:

original.SetRange original.Start, extendableRange.End

so it would be something like
dim originalRange as range
set originalRange = selection.range (or whatever you wish)

'add text
originalRange.SetRange start, end
 
G

Gavin0268

Hi Marc
Thanks again - I think I'm being really dense here, but I now get a type
mismatch with the following change. Sorry, haven't programmed in word since I
first did this several years ago, which might explain a lot!


Dim rng as Range ........

.......

Currentfilename$ = ActiveDocument.Name

If Left$(Currentfilename$, 1) = "~" Then

Select Case DocNew$

Case "FALSE"
Set rng = ActiveDocument.Range
rng.Font.Hidden = False
rng.SetRange Start:=ActiveDocument.Paragraphs(1).Range,
End:=ActiveDocument.Paragraphs(2).Range.End (debug stops here)



' Set rng = ActiveDocument.Paragraphs(1).Range
' rng.End = ActiveDocument.Paragraphs(2).Range.End
rng.Font.Hidden = True

End Select
 
M

Marc Adams [marcmyword.com]

Gavin,

If you'd like to drop me a line, do so (e-mail address removed). Perhaps
we can walk through it via phone.
 

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