Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2006

Tip: Looking for answers? Try searching our database.

Help needed: Search in Header

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Udo Fröhn - 28 Apr 2006 14:29 GMT
Hello,
I've got a problem with a Word macro: Instead of searching in the
header of the current section, it will jump to the header of the
previous section on "Selection.Find.Execute".
I can't seem to find the error. Any help's appreciated!
Thanks, Udo

Here's the code:

Sub NewHeader()
   Selection.InsertBreak Type:=wdSectionBreakNextPage
   Selection.MoveUp Unit:=wdLine, Count:=2
   If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
       ActiveWindow.Panes(2).Close
   End If
   If ActiveWindow.ActivePane.View.Type = wdNormalView Or
ActiveWindow. _
       ActivePane.View.Type = wdOutlineView Then
       ActiveWindow.ActivePane.View.Type = wdPrintView
   End If
   ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
   ActiveWindow.ActivePane.View.NextHeaderFooter
   Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter.
_
       LinkToPrevious
   Selection.Extend
   Selection.Find.ClearFormatting
   With Selection.Find
       .Text = ")"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.Find.Execute
   Selection.Delete Unit:=wdCharacter, Count:=1
   Selection.TypeText Text:="()"
   Selection.MoveLeft Unit:=wdCharacter, Count:=1
End Sub
Greg Maxey - 28 Apr 2006 15:23 GMT
Well without going into a great detail, since you don't have anything
"physically selected" the Selection search range is interpreted as the
entire document.

i don't know exactly what your end desire is, but using ranges like
this or a variation thereof:

Sub NewHeader2()
Dim i As Long
Dim oDoc As Word.Document
Dim myRng As Word.Range
Set oDoc = ActiveDocument
Selection.InsertBreak Type:=wdSectionBreakNextPage
'Get the index number of the added section
i = oDoc.Range(0, Selection.Sections(1).Range.End).Sections.Count
With oDoc.Sections(i)
 .Headers(wdHeaderFooterPrimary).LinkToPrevious = False
 .Footers(wdHeaderFooterPrimary).LinkToPrevious = False
End With
'Set search range to the new section header
Set myRng = oDoc.Sections(i).Headers(wdHeaderFooterPrimary).Range
With myRng.Find
 .Text = ")"
 .Replacement.Text = "()"
 .Execute Replace:=wdReplaceAll
End With
End Sub
Udo Fröhn - 02 May 2006 14:15 GMT
Greg Maxey schrieb:
> Well without going into a great detail, since you don't have anything
> "physically selected" the Selection search range is interpreted as the
> entire document.
[code]

Hello Greg,
back in the office - that worked, thanks!
Udo
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.