Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi

    Is there any *easy* (perhaps VB) way of searching for 'Heading 1' style in a document & then if found

    1. Insert a 'fixed' autotext in front of it (a page of information)
    2. Change 'Heading 1' to 'Heading 2'

    Original doc -> Updated doc
    1. First topic -> [fixed page of info] + 1.1 First topic

    Thanks.
    Thanks.
    Robie

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Try this macro:

    Code:
    Sub ReplaceHeading1()
      Selection.HomeKey Unit:=wdStory
      With Selection.Find
    	.Text = ""
    	.ClearFormatting
    	.Style = wdStyleHeading1
    	Do While .Execute
    	  ' Go to start of Heading 1 paragraph
    	  Selection.Collapse Direction:=wdCollapseStart
    	  ' Insert AutoText
    	  ActiveDocument.AttachedTemplate.AutoTextEntries("Blahblah").Insert _
    		Where:=Selection.Range, RichText:=True
    	  ' Find the Heading 1 paragraph again
    	  .Execute
    	  ' Change style to Heading 2
    	  Selection.Style = wdStyleHeading2
    	  ' Go to the end of the paragraph
    	  Selection.Collapse Direction:=wdCollapseEnd
    	Loop
      End With
    End Sub

  3. #3
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='796403' date='05-Oct-2009 16:19']Try this macro:

    Code:
    Sub ReplaceHeading1()
      Selection.HomeKey Unit:=wdStory
      With Selection.Find
    	.Text = ""
    	.ClearFormatting
    	.Style = wdStyleHeading1
    	Do While .Execute
    	  ' Go to start of Heading 1 paragraph
    	  Selection.Collapse Direction:=wdCollapseStart
    	  ' Insert AutoText
    	  ActiveDocument.AttachedTemplate.AutoTextEntries("Blahblah").Insert _
    		Where:=Selection.Range, RichText:=True
    	  ' Find the Heading 1 paragraph again
    	  .Execute
    	  ' Change style to Heading 2
    	  Selection.Style = wdStyleHeading2
    	  ' Go to the end of the paragraph
    	  Selection.Collapse Direction:=wdCollapseEnd
    	Loop
      End With
    End Sub
    [/quote]

    Thanks Hans. That worked perfectly. How do you know all this? So wonderful - thank you.
    Thanks.
    Robie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •