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
enough.
- be able to position (Move) cursor by bytes, not characters.
Thank you in advance for help !
2.Problem searching for text in a range
Hi
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) & " : " & _
p_oRange.Information(wdVerticalPositionRelativeToPage)
Checksize p_oRange, l_fLeft, l_fTop, l_fRight, l_fBottom
Else
l_bFinished = True
End If
Loop
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
41123456
My Full Name
My Address Line 1
My Address Line 2
Town
City
County
Postcode
Debug.Print p_oRange.Characters.Count
84
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?
Thanks
Simon
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>
<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>
Steve
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