Range delete also removes leading space?!?

E

Ed

I set a range to encompass one line, which is an entire paragraph by itself.
This line begins with a space. After doing some things, I collapse the
range to the start and MoveStart to the beginning of the document using:
rngFind.Collapse Direction:=wdCollapseStart
rngFind.MoveStart Unit:=wdStory, Count:=-1
For debugging, I put in Range.Select - the selected text is exactly what I
want: everything from the first character of the doc to the paragraph mark
just before the original range. The now-set range does not include the
leading space of the original range.

When I delete this second range I have set, the leading space of the
original range is also removed. Is this normal and consistent Word
behavior? Is there a setting that will turn this off? Or a better way to
set the second range?

Ed
 
C

Chad DeMeyer

Ed,

Tools>Options>Edit>Smart cut and paste
is at the root of your problem. When this options is enabled, Word tries to
manage spaces between words when you copy/paste or delete them.

Regards,
Chad
 
E

Ed

Thanks, Chad. It's not that it was necessarily a large problem, but if I
give this macro to someone who doesn't have this set, and then try to do
other things, it could cause large problems. So I need to put in a "check
and see".

Appreciate the boost.
Ed
 
J

Jay Freedman

Hi Ed,

The "nice" way to do this is to save the user's current option, do
what you need, and put back the original option so the user doesn't
get upset:

Dim bOldSmart As Boolean
bOldSmart = Options.SmartCutPaste
Options.SmartCutPaste = False
' do your stuff here
Options.SmartCutPaste = bOldSmart
 
E

Ed

Thanks, Jay! I wouldn't have thought of that. but that's got to be the best
way of ensuring a "clean slate" when others run this.

Ed
 

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