Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    4 Star Lounger
    Join Date
    Oct 2005
    Posts
    599
    Thanks
    1
    Thanked 1 Time in 1 Post

    Auto replace/numbering of paragraphs (MS Word 2003)

    Hi all....I am looking for some sort of 'formula' or macro that will replace '?' with paragraph numbers. I am attaching a .txt file.

    I prefer to work with the .txt file, but I can switch to a .doc format if required.....anyway, I will generally start with the 'whole' document as shown; I will delete the paragraphs that I don't want and make some small changes to remaining paragraphs. I then want to be able to run a macro that automatically number the remaining paragraphs. At this point, I have shown the 'start' of each paragagraph with a "?", thinking that some sort of search & replace (with sequentail numbers) will do what I need.......any suggestions? Thank you.
    Attached Files Attached Files

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

    Re: Auto replace/numbering of paragraphs (MS Word 2003)

    You could run this macro:

    Sub ProcessTextFile()
    Dim strFile As String
    Dim i As Integer
    With Dialogs(wdDialogFileOpen)
    .Name = "*.txt"
    If Not .Show = -1 Then
    Exit Sub
    End If
    End With
    With Selection.Find
    .ClearFormatting
    .MatchWholeWord = False
    .MatchWildcards = False
    .Text = "?"
    Do While .Execute
    i = i + 1
    Selection.Text = i & " "
    Selection.Collapse Direction:=wdCollapseEnd
    Loop
    End With
    ActiveDocument.Close SaveChanges:=wdSaveChanges
    End Sub

    It'll let you open a text file, replace ? with a number and a space, then save and close the text file again.

  3. #3
    4 Star Lounger
    Join Date
    Oct 2005
    Posts
    599
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Auto replace/numbering of paragraphs (MS Word

    ..thanks, Hans....it appears that your macro runs in MS Word ??....will it run in a txt file...by this, I mean that I know how to make a macro in WORD, but how can I input a macro (if that's the right word) into Wordpad or Notepad (which is what seems to want to run .txt files)?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Auto replace/numbering of paragraphs (MS Word

    The macro should be stored in a module in a Word document or template and run from within Word. It uses Word VBA to manipulate a plain text file.

    Wordpad and Notepad cannot execute macros.

  5. #5
    4 Star Lounger
    Join Date
    Oct 2005
    Posts
    599
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Auto replace/numbering of paragraphs (MS Word

    I am totally lost...sorry to be so dense, but I can't understand the relationship b/w the macro you wrote..or VBA..or how to 'make it' and store it somewhere so that I can use it...I an used to working with macrso in Excel (where I can 'write' then and assign them to a button....I'm not sure what to do with the code you gave me, and, I'm not sure how to trigger the macro so that it looks for a .txt file, lerts me choose the file I want and then runs the code.....what I would normally do is open my conditions.txt file, make the changes, (perhaps save it as a new file, but maybe not), run the 'numbering' macro (without closing it -- I would want the macro to number the paragraphs and then I could copy & paste the now-numbered .txt document into my working document......

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Auto replace/numbering of paragraphs (MS Word

    Since Hans isn't online at the moment, I will try to help you.

    When you run this Macro it will display a dialog box that allows you to select the text file you want to process. All you need to do is copy Hans' code to a VBA module in a Word document and then run it.

    If you're not sure how to do this:
    <UL><LI>Open Word
    <LI>Type Alt-F11 to get to the Visual Basic Environment (VBE)
    <LI>On the Project Window choose a Word document that you want the Macro to be in
    <LI>On the VBE Insert Menu choose Module
    <LI>Paste the code from Hans' post into the new VBE module
    <LI>On the file Menu choose Save to save the word document with this new Macro[/list]To run the Macro you can now either click the VBE Run button, or in Word go to Tools > Macro > Macros..., then select "ProcessTextFile" and click Run

    StuartR

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Auto replace/numbering of paragraphs (MS Word

    This post also might help: Creating your first Macro in Word.

  8. #8
    4 Star Lounger
    Join Date
    Oct 2005
    Posts
    599
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Auto replace/numbering of paragraphs (MS Word

    Good evening, Hans....I am returning to a post that I did last week. You gave me a VBA formula (see earlier post in this thread, on March 23) and it works very nicely...I made a mistake, though....in my post, I said that I would start each paragraph with a "?" and I was looking for VBA code that would replace the ?s with sequential numbers.....in actual fact, each paragrapah now starts with a number (in sequence) from 1 - 50. I plan to delete various paragraphs, to suit the situation: eg: I might delete paragr 4,7,15,19,32......I need the VBA code to auto-renumber the remaining paragraphs in sequence (ie: paragr 5 becomes 4, 6 becomes 5 etc etc).......can you tell me how to change the code you gave me last week so that it will do this? Thank you....ps: I can also use #? and then have the VBA re-number the remaining paragraphs and remove the '?' if that is easier....thanks again

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Auto replace/numbering of paragraphs (MS Word

    In that case, I would use a Word document instead of a text file, and use Word's built-in List Number style. Word will automatically adjust the numbering if you add or remove paragraphs with this style. No coding needed at all.

  10. #10
    4 Star Lounger
    Join Date
    Oct 2005
    Posts
    599
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Auto replace/numbering of paragraphs (MS Word

    I would ordinarily have done that, but the reason I can't is b/c the document that is being composed must be in .txt format so that it can be copied and pasted into another 'document'......what I am doing is composing a document in WORD and then converting it into txt b/c txt is the only format that I can use when dropping it into this second document.....this second doc is composed in software that is hopelessly out-dated but it is what I have to work with...so, I compose my list as a .doc (from my template), save it as a .txt and then copy & paste.....a document composed as .txt in Notepad or Wordpad doesn't permit numbering of paragraphs (as far as I can see..)....so, it's easier to do it in WORD, save it as a .txt, and then autorenumber the paragraphs.......hope this explains it better.....so I thought I could use the VBA code you gave me, but instead of searching for "?", it could search for #?...or # and sequentially number the paragraphs.....any suggestions?

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Auto replace/numbering of paragraphs (MS Word

    If you use #? or # as placeholder, you can use the code I posted previously, you only need to replace "?" with "#?" or "#".

  12. #12
    4 Star Lounger
    Join Date
    Oct 2005
    Posts
    599
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Auto replace/numbering of paragraphs (MS Word

    Well, I tried that...using a numbering convention such as 1?, 2?, 3?...I also used ?1, ?2, ?3 etc, thinking that your amended code would replace 1? with 1, (and if I deleted para 2, then para 3 would become 2 and would be renumbered from 3? to 2......but it doesn't seem to work.....and b/c there are 50-some paragraphs, I pretty much have to number them ( to compare para 1 with para 1?)...if I just number them as ?, or *? or #?, then the composition of the 'copy & paste' doc (where I delete certain paragraphs etc and amend others) would require me to read & compare each paragraph to ensure that I am deleting (or not) the correct paragraph...

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Auto replace/numbering of paragraphs (MS Word

    Sorry, I thought you meant # as a literal character.

    Since you're doing this in Word anyway, why not set up the entire document in Word, where you can use the built-in numbering facilities, and save as a text file at the last moment, before you need it in the prehistoric software?

  14. #14
    4 Star Lounger
    Join Date
    Oct 2005
    Posts
    599
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Auto replace/numbering of paragraphs (MS Word

    ..probably b/c I can never figure out the built-in numbering with WORD and my experience is that it is so fickle, that the frustration of using that part of WORD is not worth the hassle.....espec when trying to number paragraphs that have sub-paragraphs etc etc...the numbering never seems to 'stick' and I always have to begin at the beginning.....

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Auto replace/numbering of paragraphs (MS Word

    The trick is *not* to use the Numbering button on the toolbar or the Format | Bullets and Numbering dialog, but the built-in List Number style. By applying that style to the paragraphs you want to number, you can obtain consistent results.

Page 1 of 2 12 LastLast

Posting Permissions

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