Problem with Range.Text



  • 1. Removing blank spaces and section breaks
    Hello Using Office 2002 SP-2, Windows 2000 V5.0 SP-4. I have a Word template with a userform where users can tick checkboxes to include blocks of text. If a box is left unticked the corresponding block of text is deleted from the document. The document initially contains all the text and pieces are removed if their box is unticked. My problem is that I am left with large blank spaces in the document which need to be removed. Also, if an entire section has been deleted I need to remove the section break as well. I haven't been able to find a way of doing this through VBA and would very much appreciate any help. Thanks Denise Crawley
  • 2. How to improve reformance in mac
    Hi, I am using formfield controls in word vba application. How can I improve the application performace in Mac (i.e Word Mac x). Application get flickers in Mac. How to overcome from these problems. Can anybody help me. Thanks & Regards Naveen
  • 3. VBA search for text string in non-Word doc?
    I am using TextStream to create documents. I also need to grab several text strings from the documents. At the moment, I create and save the doc with TextStream, then reopen it with Word and do my searches. This adds a monumental amount of time to running this program. Is it possible to search it with Word VBA as a non-Word document as it's created and while it's still open? Code to create doc: Set docTIR = fs.CreateTextFile(strNewDoc) docTIR.Write (strNewTIR) docTIR.Close Ed
  • 4. Using two passwords in a macro
    I installed a tremendously benificial macro that allows me to use SpellCheck in locked forms. We have hundreds of these locked forms. and some of them have different passwords to lock them. Is it possible to have the macro recognize at least two passwords?

Problem with Range.Text

Postby Neo » Sun, 05 Jun 2005 07:07:05 GMT

Hello All,

I want to get text in Range object. But I am also interested in
numbered list formatting. e.g. if text is

1. x
2. y

I want it to be as above. Althoug Range.Text gives me only

I realized if I save it in text file I can get numbers. Also, I figured
out copy /paste preserves numbered list.

but I am looking for something elegant. Is there any way to get Text in
range with numbered list data???

Best Regards,
Pravin A. Sable

Re: Problem with Range.Text

Postby Jezebel » Sun, 05 Jun 2005 09:39:13 GMT

Explore the range's ListFormat object. ListNumber gives you the absolute 
number; ListString gives you the number as actually displayed.

If your Range includes more than one paragraph, the properties show the 
values for the first paragraph; or you can iterate the Range's 
ListParagraphs collection.

Re: Problem with Range.Text

Postby Neo » Sun, 05 Jun 2005 12:40:08 GMT

Thaks it worked!

    Dim para As Paragraph
    Dim paras As Paragraphs

    Set paras = r.Paragraphs
    Dim sLine As String
    Dim i As Integer
    i = 1
    Do While i <= paras.Count
        Set para = paras(i)

        sLine = sLine  & para.Range.ListFormat.ListString & " " &
       i = i + 1

Similar Threads:

1.Range.Text and Range.Characters

Dear colleagues, 

I develop MS Word Add-in , the goal is to perform specific search in Word 
docment and then set cursor to found positions. 

Range.Characters returns a collection of single- of double-byte characters. 
The case of double-byte chars is e.g. document with a table. Table contains 
some "D7" charatcers. 

Characters is too slow way to access the whole document text, so I use 
Range.Text. However, Text returns me a string of single-byte characters. D 
and  7 are two separate characters , so Range.Text turns out to be longer 
than Range.Characters.Count. 

This becomes a problem , when I use Range.Move to set cursor to positions 
found in Range.Text . Move uses the same way as Characters, i.e. D7 is single 
character. So cursor position becomes incorrect. 

I need at least one of the following : 

- be able to get text as multibyte string, where two-byte character is one 
character. Collecting text from Charatcers property does not work quickly 

- be able to position (Move) cursor by bytes, not characters. 

Thank you in advance for help !

2.Problem searching for text in a range


I have this code

    'set leftmost, rightmost, topmost, bottommost positions to extremes
    l_fLeft = m_oWordDoc.PageSetup.PageWidth
    l_fTop = m_oWordDoc.PageSetup.PageHeight
    l_fRight = 0
    l_fBottom = 0

Debug.Print p_oRange.Text

    Do While Not l_bFinished
        p_oRange.Find.Execute vbCr, Forward:=True
        If p_oRange.Find.Found Then
                Debug.Print p_oRange.Start & " : " & p_oRange.End,
p_oRange.Information(wdHorizontalPositionRelativeToPage) & " : " & _
                Checksize p_oRange, l_fLeft, l_fTop, l_fRight, l_fBottom
            l_bFinished = True
        End If

I'm trying to find all vbCr characters in the range I'm passing in and find 
the rightmost and bottommost vbCr's.  (Actually I'm trying to get the left, 
top, right, bottom dimensions of the range and this was the only way I could 
think about doing it.)

The range is subsection of a word document.

Debug.Print p_oRange.Text
 My Full Name
My Address Line 1
My Address Line 2

Debug.Print p_oRange.Characters.Count

When I run through this loop, it seems to be searching beyond the end of the 
range being passed in. Here's the result of the debug.print statement in the 
middle of the loop

10 : 11       180.75 : 72
24 : 25       162.75 : 112.5
42 : 43       183 : 126.75
60 : 61       167.25 : 140.25
65 : 66       117.75 : 151.5
70 : 71       111 : 165.75
77 : 78       126 : 179.25
88 : 89       143.25 : 193.5  <=== *
106 : 107     250.5 : 207     <=== *

*These values are beyond the end of the range I passed in and I can only
assume they are the next vbCr's in the document.

What am I doing wrong? I thought that the Find.Execute would be restricted
to look between the start and end of the range? Have I misunderstood?



3.Field text range problem

Version: 2008
Operating System: Mac OS X 10.5 (Leopard)
Processor: Power PC

In my applescript, I need to find out if the user has put the cursor in a field at the time the script is run.   <br>
There is no inField function and I can't seem to get a (start of / end of) text range of a field relative to the start of the document, for each field when looping through all the fields. <br>
I realize that text ranges contain fields.  This makes it confusing that I am trying to find a text range or selection object that may be in a field. <br><br>Here is a little script I was testing: <br>
tell application "Microsoft Word" <br>
        repeat with fieldnum from 1 to fieldcnt <br>
                set show codes of field fieldnum to true <br>
                set myrange to content of field code of field fieldnum of active document <br><br>		if ((start of myrange) > thisRange) and (thisRange > end of myrange) then <br>
                        display dialog "in field " & fieldnum <br>
                else if (start of myrange > thisRange) and (thisRange < end of myrange) then <br>
                        display dialog "after field " & fieldnum <br>
                else if (start of myrange < thisRange) then <br>
                        display dialog "before field " & fieldnum <br>
                else <br>
                        display dialog "unknown" <br>
                end if <br>
                --display dialog "start " & (start of myrange) as text <br>
                --display dialog "end " & end of myrange as text <br>
        end repeat <br>
end tell <br><br>Also,  has anyone gotten the command "offset" to work from within a tell application "Microsoft Word" section?  It is in the dictionary, but always returns an access denied (or something similar) error. <br><br>Thanks,  <br>

4.Tabel Cell range text problem

I am having a problem adding text to a cell in an existing table
it seems to be pre-appending my text to the current text as opposed to 
overwriting which is what I need.

my code is in C#
cell = table.Cell(curRow, 1); // the first column

Word.Range cellRange = cell.Range; //cellrange = 
cell.Range.Paragraphs.Item(1).Range; didn't either work

string dd = cellRange .Text;  //dd -  will show as "1\n\a" in the debugger

int currentBuilding = 5;

cellRange.Text = currentBuilding.ToString(); //replace the text with 5

dd = cellRange .Text; ////dd -  will show as "51\n\a" in the debugger

5.Range.Text - AllCaps problem

6. Range.Text method and problem with special chars

7. Tabel Cell range text problem

8. T abel Cell range text problem

Return to MS WORD


Who is online

Users browsing this forum: No registered users and 63 guest