Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Jul 2008
    Posts
    36
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi !
    What's the wrong with this code? I have many paragraphs in my document. Each Paragraph begins various number as text. I want to renumbering all of them as text. It's working when I pres F8 button ono by one in the VB section. But It's not working when I press RUN on my current document!
    Yken

    Code:
    Sub renumbering()
    	Dim par As Paragraph
    	Dim Words As String
    	Selection.HomeKey Unit:=wdStory
    	Words = 1
    	For Each par In ActiveDocument.Paragraphs
    			Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
    			If IsNumeric(Selection) Then
    			Selection = Words
    			Words = Words + 1
    			End If
    	Selection.EndOf Unit:=wdParagraph, Extend:=wdMove
    	Next par
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    [quote name='yken' post='761420' date='25-Feb-09 14:19']What's the wrong with this code?[/quote]

    You have confused the use of ranges and selections.

    If you are going to use code like
    For Each par In ActiveDocument.Paragraphs
    then you should not go on to manipulate the selection with lines like
    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
    Instead you should manipulate the paragraph by using the variable par with code such as
    Code:
    Sub renumbering()
    	Dim par As Paragraph
    	Dim Words As String
    	Selection.HomeKey Unit:=wdStory
    	Words = 1
    	For Each par In ActiveDocument.Paragraphs
    		If IsNumeric(par.Range.Words(1)) Then
    			par.Range.Words(1).Text = Words & " "
    			Words = Words + 1
    		End If
    	Next par
    End Sub

  3. #3
    Lounger
    Join Date
    Jul 2008
    Posts
    36
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thank you so much!
    Yken

Posting Permissions

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