Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #11  
Old 01-03-2012, 02:49 PM
macropod's Avatar
macropod macropod is online now Please help copy inside brackets Windows 7 64bit Please help copy inside brackets Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,514
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Jana,
Quote:
Is it possible to this fault, the fact that im using office 2010?
No. I developed the code on Office 2010. The error suggests the document you're running the code on does not have a Style named 'Heading 2'.

The following version of the code should work with whatever your Word installation calls these Styles:
Code:
Sub InsertRefs()
Application.ScreenUpdating = False
Dim RngHd2 As Range, RngHd3 As Range, RngRef As Range, oPara As Paragraph
Dim Hd1 As String, Hd2 As String, Hd3 As String
With ActiveDocument
  Hd1 = .Styles(wdStyleHeading1).NameLocal
  Hd2 = .Styles(wdStyleHeading2).NameLocal
  Hd3 = .Styles(wdStyleHeading3).NameLocal
End With
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ""
    .Style = Hd2
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  Do While .Find.Found
    Set RngHd2 = .Paragraphs(1).Range.Duplicate
    With RngHd2
      On Error GoTo ParaLast
      While .Paragraphs.Last.Next.Style <> Hd1 And .Paragraphs.Last.Next.Style <> Hd2
        .MoveEnd wdParagraph, 1
      Wend
ParaLast:
      If .Paragraphs.Count > 2 Then
        Set RngRef = RngHd2.Paragraphs(3).Range.Characters.Last
        .MoveStart wdParagraph, 3
        Set RngHd3 = RngHd2
        With RngRef
          .MoveEnd wdCharacter, -1
          .InsertAfter " { "
          For Each oPara In RngHd3.Paragraphs
            If oPara.Style = Hd3 Then
              If Len(Trim(oPara.Range.Text)) > 1 Then
                .InsertAfter Left(oPara.Range.Text, Len(oPara.Range.Text) - 1) & ", "
              End If
            End If
          Next
          .Characters.Last.Previous.Delete
          .InsertAfter "}."
        End With
      End If
    End With
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Gray square brackets waldux Word 8 09-25-2013 04:14 PM
Please help copy inside brackets Find/Replace Brackets Problem fatso Word 2 08-04-2011 11:34 AM
brackets citation uncung Word 1 07-13-2011 01:39 PM
Brackets Issue... DarkJudge1 Outlook 0 07-06-2010 05:15 PM
copy a file which does not have copy option jkind Word 0 01-17-2010 09:25 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:57 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft