Use a variable for number of characters to select in macro

S

Susan L

I am setting up some macros to help in restructuring a large number of tables
in Word. I'm recording them, since I'm not familiar with VBA in Word.

In this part of the macro, text is selected over to the paragraph marker
(which is then deleted). These lines of text can vary in length from table to
table.

Here is what is in the macro:

Selection.MoveRight Unit:=wdCharacter, Count:=46, Extend:=wdExtend
Selection.Cut

Is there a variable I can use in Count:= to ensure the selection goes to the
end of the text line?
 
D

Doug Robbins - Word MVP on news.microsoft.com

Use:

Dim drange As Range
Set drange = Selection.Range
drange.End = Selection.Paragraphs(1).Range.End
If drange.End = Selection.Cells(1).Range.End Then
drange.End = drange.End - 1
End If
drange.Delete


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
S

Susan L

Doug: My apologies for not responding earlier.

It works well. I get the full line of text when I paste. It does seem to
copy the paragraph marker, despite the -1 in the code.

What I do with the string that's been cut is to arrow up in a table and
paste it into a line that already contains another string. So the new
paragraph marker moves the line up and removes the applied style.

This is not a "biggie" as I'm becoming a macro recording artist :) I can
arrow around the problem. But maybe there's a simple answer? If not, I am
delighted with what you've given me because I can move forward.
 

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