Closed Thread
Results 1 to 3 of 3

What's the wrong with this code?

  1. #1
    Registered User
    Join Date
    02-26-2009
    Location
    India
    MS-Off Ver
    Access
    Posts
    46

    What's the wrong with this code?

    Hi,

    I have many paragraphs in my document. Each Paragraph begins various number as text. I want to re-numbering all of them as text. It's working when I press F8 button one by one in the VB section. But It's not working when I press RUN on my current document!
    Yken
    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
    Webtekr
    Guest

    Re: What's the wrong with this code?

    Hi,

    You have confused the use of ranges and selections.

    I m sending you the code this will helps u just check it....

    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

    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
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: What's the wrong with this code?

    champs & Webtekr

    Both of your posting in this thread break Forum rule 3

    Please take a couple of minutes and read ALL theForum Rules then wrap your VBA code (Rule 3)
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1