VBA numbering

P

Phoenix

Hi,

i'm having trouble trying to retrieve the numbering assigned to a
paragraph.

if the number is manually added to the line then i can get the value
with ease through the range variable, but if all numbers are generated
via the word numbering system they do not show through the range
option.

Does anyone know how i can get hold of the value

thanx in advance

James
 
G

Greg

Sub Scratchmacro()
Dim myRng As Range
Set myRng = Selection.Paragraphs(1).Range
MsgBox myRng.ListFormat.ListString _
& " " & myRng
End Sub
 
P

Phoenix

I have tried this method and only get an empty string back from the
query. Do you know of any other ways that i could get hold of the
value.

thanx in advance

James
 
G

Greg Maxey

Of course I don't know exactly what it is that you are doing. In this case,
if you put your cursor in a Word paragraph that contains text and run the
macro I provided I don't see how it is possible to return and empty string.
Sorry.
 
P

Phoenix

i have to call this macro from a c# application. so the number is being
inserted into a text file which can then be read by the application.

so from your above comment if i manage to get the macro to select the
line then run your macro i should get the values i require.

Cheers
 
G

Greg

Phoenix,

My macro is very simplistic. It is intended to illustrate how the list
numbered paragraph's text range and list string can be combined and
displayed by a message box. You will most likely want to adapt my
macro to suit your specific needs.
 
P

Phoenix

i have tried your macro would it be possible for you to e-mail your
sample to me. Then i can see where i'm going wrong.

Thanx
 
J

Jonathan West

Phoenix said:
i have tried your macro would it be possible for you to e-mail your
sample to me. Then i can see where i'm going wrong.

Thanx

Greg has already posted here all the code that he has written for you. Place
that code in a VBA project, position the cursor in the paragraph whose
numbering you want to check, and run the macro.

It is a demonstration of concept - it displays a message box showing the
ListString of the paragraph that the cursor currently occupies. That is
almost certainly not what you want to do, but the code shows you which part
of the object model you have to use in order to do what you want.

You have already worked out how to get the number if it is manually typed
in. With the same Range object that you used there, get the
ListFormat.ListString property. That will give you the number you want.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
P

Phoenix

I have tried now and got the demonstration submitted by greg working.
still through the range i cannot get the number it return a "" empty
quote, any other ideas

Thanx
 
P

Phoenix

I have managed to get this working to a degree. the problem still
exists when the item is more situated 2 or more indents. is there
another function that i have to make use of to get this value or is it
a problem with 2003.

thanx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top