#1
|
|||
|
|||
Please help copy inside brackets
Is there any way to take the text of specific heading numbers and to take to the previous heading text inside brackets separated by · before the last full stop. I need something to take the title to copy inside brackets and if more than one headings to seperated by comma and end to a fullstop. |
#2
|
||||
|
||||
Hi Jana,
So what you want is for each heading 3 to be repeated at the end of the 2nd physical (1st logical) paragraph after the corresponding heading 2 - and for the heading 3 entries thus repeated to be separated by commas and, as a group, enclosed in braces? If so, most of what you want can by done by inserting cross-references to the heading 3 paragraphs at the appropriate point. This has the advantage that they'll update if the heading content changes. If you have a lot of these, it could be automated via a macro.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Quote:
I have a lot of this, thats for sure!!! No i dont want to add crossreferences because already included and maybe cause problem. I need to add these inside brackets. |
#4
|
||||
|
||||
Hi Jana,
I'm not sure what problems you're anticipating by inserting cross-references within the braces. The most I'd expect is that, if the heading gets deleted, the cross-reference would generate an error message. Being readily recognised, that may be better than having output that still refers to a deleted heading.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Quote:
|
#6
|
||||
|
||||
Hi Jana,
Try the following macro: Code:
Sub InsertRefs() Application.ScreenUpdating = False Dim RngHd2 As Range, RngHd3 As Range, RngRef As Range, oPara As Paragraph With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "" .Style = "Heading 2" .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 <> "Heading 1" And .Paragraphs.Last.Next.Style <> "Heading 2" .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 = "Heading 3" 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] |
#7
|
|||
|
|||
Error Compile
I try to execute this code but the execution returns compile error. So, I try to see the code and a yellow text Subinsertrefs(), also the line Dim RngHd2 As Range, RngHd3 As Range, RngRef As Range, oPara As Paragraph With ActiveDocument.Range looks like with red lettering. Maybe a problem with that too.
|
#8
|
||||
|
||||
Hi Jana,
That suggests you haven't copied & pasted the code correctly. What did the 'Compile Error' message say was the problem? You need to be especially careful that the copied & pasted code has exactly the same content and layout as in my post.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Error 5834
Heading 2 yellow error.
|
#10
|
||||
|
||||
Hi Jana,
That error does not occur if you run the code on the document attached to your previous post.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
Ha ha!!! Not we take the same problem
Still yellow color. Look the document.
|
#12
|
||||
|
||||
I get no error and the code executes correctly!
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
Dear Macropod
I dont understand what misunderstand, i still get this error. Maybe something i ve done before. But still not working for me. Whats the problem with that?
|
#14
|
||||
|
||||
Hi Jana,
Try the attached. It''s your original 'without formation' document with the macro added and zipped (we can't add docm attachments). It works for me.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#15
|
|||
|
|||
Macropod thanks very much for your help
Please i tried again and the heading 2 is still yellow. Maybe is problem with my word processor.
|
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Gray square brackets | waldux | Word | 8 | 09-25-2013 04:14 PM |
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 |