PDA

View Full Version : Deleting number from list



see3po81
01-13-2009, 11:56 AM
First post for me here. I am new to VBA and could use a little help.

I have been working on some code to edit bookmarks in a report that I have.

One of the things I am doing is editing an existing numbered list in Word based on user selection.

I can easily change text within the list just using bookmarks. When I try to delete a line from the list, I run into a problem with the numbering. I am confused at how to get the code to recognize to delete the entire line and number. As of now it just deletes the line and leaves the number there (with a blank line)

Can anyone help or point me in the right direction.

Thank You

lucas
01-13-2009, 12:13 PM
You need to look at paragraph I think...

see3po81
01-13-2009, 12:19 PM
thank you for the quick reply.

I played around with .paragraphs

I deleted the specific paragraph line, all the text is deleted but the number still remains.

ex. If oForm.optcatIII = True Then ActiveDocument.Paragraphs(64).Range.Delete

where "oForm.optcatIII" is the user defined action of selecting an option button

lucas
01-13-2009, 12:37 PM
Is the number a bulleted type number?

The numbers in these paragraphs where added that way and it works.....

we're missing something.

see3po81
01-13-2009, 12:47 PM
that is the perfect example for what I am trying to do.

The problem I run into is when I delete the first paragraph and not the second or third or so on. That is when I get my error.

When I change your example code to paragraphs(1), instead of "2" nothing happens.

lucas
01-13-2009, 02:41 PM
I got busy so don't give up.....

I'm thinking collapse or ListFormat if you have time to do some research until I can get back.....

lucas
01-13-2009, 03:08 PM
Ok, just to check in. In the example I posted it deleted para 2 and you said it wouldn't delete para 1.

Well I finally changed one of the words and now instead of it being
1. test
2. test

it reads
1. apple
2. test

I set the code to delete para 1 and apple disappears but test is renumbered to 1 so it is deleting paragraph 1....

dc4life78
01-15-2009, 07:54 AM
Since no one seems to be able to solve the issue I posted at least I can try to help someone else...

This works for me to select the list number:

Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oParagraph As Word.Paragraph

Set oWord = New Word.Application (or whatever file you are manipulating)
Set oDoc = oWord.Documents(1)
Set oParagraph = oDoc.Paragraphs(# of line you are manipulating)

oParagraph.Range.Select
oWord.Selection.Paragraphs(1).SelectNumber
oWord.Selection.Delete Unit:=wdCharacter, Count:=1

I'm sure tons of folks do this, but what has helped me immensely in programming in Word VBA is creating a macro in Word, using the Macro recorder and doing whatever it is I am trying to automate, then edit the macro in VB to see the code that gets it done.

Hope this helps!

see3po81
01-15-2009, 08:02 AM
thanks guys for the help