cut macro fails to put text on clipboard

T

Terry.Murphy3

Hi - I'm running Word 2000 sp3 on a pc running XP sp3 and have a macro that
selects a partial line of text and then is supposed to insert it 3 lines
further down the page:

Selection.MoveRight unit:=wdCharacter, Count:=44
Selection.MoveRight unit:=wdCharacter, Count:=32, Extend:=wdExtend
Selection.Cut
Selection.HomeKey unit:=wdLine
Selection.MoveDown unit:=wdLine, Count:=3
Selection.TypeText Text:=vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & _
vbTab & vbTab

' move line right one character
Selection.TypeText Text:=" "
Selection.Paste

However, when the text is cut it disappears from the doc but is NOT placed
on the clipboard. Consequently the paste fails. Where does it go and how do
I get it back?

The real kicker is that it works about 2% of the time - but I don't know
when that 2% will happen...

Any help will be greatly appreciated -

Thanks - Terry
 
D

Doug Robbins - Word MVP

Use

Dim rng As Range
Set rng = Selection.Range
rng.Start = rng.Start + 44
rng.End = rng.Start + 32
Selection.HomeKey unit:=wdLine
Selection.MoveDown unit:=wdLine, Count:=3
Selection.Text = vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & _
vbTab & vbTab & vbSpace & rng.Text
rng.Delete

or

Dim rng As Range
Dim strText As String
Set rng = Selection.Range
rng.Start = rng.Start + 44
rng.End = rng.Start + 32
strText = rng.Text
rng.Delete
Selection.HomeKey unit:=wdLine
Selection.MoveDown unit:=wdLine, Count:=3
Selection.Text = vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & _
vbTab & vbTab & vbSpace & strText


I don't like using all the vbTabs

--
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
 
T

Terry.Murphy3

Thanks Doug!! Since I'm here at work this morning I'll give this a try. I
don't particularly care for the vbTabs either. I'm just learning this
(slowly) and couldn't come up with any other way to move the insertion point
to that location. If you've got a better idea...

Also, the next thing before the 'paste' is to determine if the space just to
the right of the HomeKey location is a paragraph mark or a 'space'
character. If it's space character I need to 'skip' over some text to the
location where I end up with all the vbTabs and then do the paste.

I REALLY appreciate your help!

Terry
 
G

Graham Mayor

It would be easy enough to move text to a new location, but your macro does
not convey a true description of the document, what it is you are moving and
to where. Can you describe exactly what you want to move and to where in
relation to the moved text. When you talk about 'lines' are the 'lines'
separate paragraphs, or are they flowed lines - or even rows of a table?. Is
the location you are moving to in the same paragraph or another paragraph?
What is the function of all those tabs?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

Terry.Murphy3

I tried to reply to this last Saturday but the website froze and I've just
gotten back to it today-

I'm taking a text file and using Word to rearrange the data so that it fits
into specific blocks on a pre-printed form.

This, in part, is what I'm manipulating:

Â
........................................................xx-xxx-xxx...............00¶
¶
¶
...........WANDA L
Querry.....................1-0-0695-14...........OJT........¶
...........APT 4A........................................................¶
...........1234 THICKET LN..............................................¶
...........INDIANAPOLIS IN 12345................................¶

¶
¶
¶
¶
¶
Normally there are only 3 address lines and with what Doug Robbins (bless
him) supplied I am able to move the '1-0-0695-14.........OJT' text down to
what is, in the above sample, the 4th address line. It's just super.

However, what can I do to move the same text to the same place when the CSZ
info is on the 4th address line?

Thanks! = Terry
 
G

Graham Mayor

What I suspect you need, based upon your description (and assuming the line
you want moving always contains OJT) is

Dim oPara As Paragraph
Dim sText As String
Dim i As Long, j As Long
For i = 1 To 9
Set oPara = ActiveDocument.Paragraphs(i)
If InStr(1, oPara, "OJT") Then
sText = oPara.Range.Text
oPara.Range.Delete
Exit For
End If
Next i
For j = i To 12
Set oPara = ActiveDocument.Paragraphs(j)
If Len(oPara.Range) = 1 Then
oPara.Range.Text = sText
Exit For
End If
Next j


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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

Similar Threads


Top