Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Borders In Headers

Status
Not open for further replies.

vnk

IS-IT--Management
Nov 14, 2001
33
US
Hi,

I am trying to insert borders(top & bottom) in headers
of a MsWord document.
I have recorded a macro to put a border in header and
footer but it doesn't work for the whole document.
I believe its happening because the document is divided into
different sections.
Please help me in getting this.
Any help is appreciated.
 
Try something like:

Sub BordersInHeaders()

Dim s As Section

For Each s In ActiveDocument.Sections
With s.Headers(wdHeaderFooterPrimary).Range
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
End With
End With
With s.Footers(wdHeaderFooterPrimary).Range
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
End With
End With
Next s

End Sub

You may need to repeat for "first Page headers" and "even page headers", if these have been defined.

M :)
 
Wow! It worked wonderfully.

Thanks Again Mossoft!

I have one more hurdle....I know am asking too many things,
am helpless buddy.

I have a document with First Name :"John" occuring multiple
times, i want my script to delete the whole line
when it finds 'First Name :"John" '.
I have recorded a script and modified it but all
it does is replace the word.
Thanks, In Advance.
VNK
 
Sub RemoveName(i_strName as string)

Selection.HomeKey Unit:=wdStory

With Selection
With .Find
.MatchWholeWord = True
.Text = i_strName
.Execute
End With

While .Find.Found
.HomeKey Unit:=wdLine
.EndKey Unit:=wdLine, Extend:=wdExtend
.Delete Unit:=wdCharacter, Count:=1
.Find.Execute
Wend
End With

End Sub

M :)
 
Thanks Again!
It does work.
One quick thing, I have run these scripts on Office2000 with
Windows 95' and everything works fine. But when I ran
these scripts on Office2000 with Windows2000 and XP, it
hung up.
Do we need to change any parameters or Environmental variables??

Thanks,
VNK.
 
All above code is dependant on the Word object library being referenced. Can't see why it wouldnt work in different OS (I'm running NT/Off2000 and all is well).

Can you be more specific about the error? Where/When does it 'hang'?

M
 
Mossoft,

I dont know specifically where it is hung up. Can I put
some msg boxes after each operation? Do you think that
will provide more info.

Thanks,
VNK.
 
Liberal scattering of 'msgbox's (if you prefer) or put a 'Stop' (or a breakpoint) at the top of the functions and single step through them using F8.

In the first instance - whether it compiles OK or produces a run-time error would be useful.

When it 'hangs', maybe it is just busy - try Ctrl+Break then single step through code to try and work out why.

Now maybe a good time to mention that I left out the error traps for simplicity - may also be a good time to put them back!!

M
 
Hi,

I found what was the problem......
In first instance on Win95/98 I had no problems when I ran this program.

Sub RemoveName(i_strName as string)

Selection.HomeKey Unit:=wdStory

With Selection
With .Find
.MatchWholeWord = True
.Text = i_strName_first_find
.Execute
End With

While .Find.Found
.HomeKey Unit:=wdLine
.EndKey Unit:=wdLine, Extend:=wdExtend
.Delete Unit:=wdCharacter, Count:=1
.Find.Execute
Wend

With Selection
With .Find
.MatchWholeWord = True
.Text = i_strName_Second_find
.Execute
End With

While .Find.Found
.HomeKey Unit:=wdLine
.EndKey Unit:=wdLine, Extend:=wdExtend
.Delete Unit:=wdCharacter, Count:=1
.Find.Execute
Wend

End With

End Sub
But on Win2K, I had to insert "Selection.HomeKey Unit:=wdStory" before each search like......


Sub RemoveName(i_strName as string)

Selection.HomeKey Unit:=wdStory

With Selection
With .Find
.MatchWholeWord = True
.Text = i_strName_first_find
.Execute
End With

While .Find.Found
.HomeKey Unit:=wdLine
.EndKey Unit:=wdLine, Extend:=wdExtend
.Delete Unit:=wdCharacter, Count:=1
.Find.Execute
Wend

Selection.HomeKey Unit:=wdStory
With Selection
With .Find
.MatchWholeWord = True
.Text = i_strName_Second_find
.Execute
End With

While .Find.Found
.HomeKey Unit:=wdLine
.EndKey Unit:=wdLine, Extend:=wdExtend
.Delete Unit:=wdCharacter, Count:=1
.Find.Execute
Wend

End With

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top