Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

Replace selection.range Word bug?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
FK - 29 Mar 2005 14:51 GMT
Hi,

For several years I've coped with this problem, but now I really want (need)
a solution. I hope any of you can help me out.

What's the case, well in Word XP (and 97 and 2000), if I try to change the
contents of a selected range in a table in a frame, it goes wrong. I've
tried to replace the text directly, and tried first emptying the selection.
In the text is for example '[test]' selected.

- When I use selection.range.text="" then Word leaves 't]' while it
shouldn't.

- When I use selection.range.delete, surrounding spaces are also deleted. If
I put a space in front and in back of '[test]' then it leaves just the one
space instead of two.

- When I use selection.typetext text:="replacement", the spaces also get
messed up.

The ever so strange thing is that it doesn't go wrong in a normal text, or
in a normal table (not in a frame). When I say frame I mean a to a frame
converted textbox (Or a table created in Word 2003 which is always a table
within a frame?)

Extra info:

I search for 'codes' in the text and based on the contents of the 'codes' I
replace them with a certain text. So I cannot use the standard Find/Replace
functions. And somehwat I do use it, just a little split up, find first and
do something and replace.

TIA!

--

Ronald Pothuizen
Klaus Linke - 30 Mar 2005 23:51 GMT
Hi Ronald,

Two reasons why things might go wrong:

-- The Range of a table cell has two formatting characters (end-of-cell-marker = CHr(13) & Chr(7)) at the end.
If you aren't aware of that, you might go wrong by two characters.
(If I use Selection.Range.Text = "" on a cell it always deletes the text, no matter whether the whole cell or only the text was selected. But maybe your code is a bit more complicated?)

-- Look at your "Smart cut and paste" options in "Tools > Options > Edit". They explain why spaces you didn't select sometimes get deleted, or spaces get inserted when you insert text. The same should happen in the user interface (Del or Backspace key) with your settings.

If you like that in the user interface, but don't like it in your macros, you can temporarily change the settings.

Dim oldPasteAdjustWordSpacing As Boolean
Options.PasteAdjustWordSpacing = False
' ... your code ...
Options.PasteAdjustWordSpacing = oldPasteAdjustWordSpacing

Some other options might also apply... If you keep having problems, you might check them out, or check if the same thing that goes "wrong" in your macro also happens in the user interface.
Say, Selection.Delete will delete the character to the right of an insertion point (nothing selected) ... something you might not expect, but the same as happens with the Del key.

Greetings,
Klaus

> Hi,
>
[quoted text clipped - 33 lines]
>
> Ronald Pothuizen

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.