Cutting and Pasting from a source doc to a target doc

  • Thread starter Thread starter Buster
  • Start date Start date
B

Buster

Hi,

I am trying to cut and paste different paragraphs from one
document into another document. In the main document, I
put check boxes that do some code to copy and paste the
information into another document. I am having trouble
nagigating the cursor to the end of the first selection in
the destination document. When I choose the second
paragraph from the main document, it copies over the lines
from the first selection.

How do I ensure that the cursor is always at the end of
the last selection when I want to paste the data?

Any help would be great..

-Buster
 
Here is the code.

Private Sub PARA1_Click()

If PARA1.Value = -1 Then
ActiveDocument.Paragraphs(1).Range.Copy
Documents.Add
ActiveDocument.SaveAs FileName:="C:\Documents and
Settings\jmielke\Desktop\REPORT.doc"
ActiveDocument.Range.Paste
Selection.MoveDown Unit:=wdParagraph, Count:=1

With ActiveDocument.Content
.InsertParagraphAfter
.InsertAfter Chr(10)
End With

Selection.MoveDown Unit:=wdLine, Count:=1

ActiveDocument.Save

Documents("test.doc").Activate

Else


End If

End Sub

Private Sub PARA2_Click()

If PARA2.Value = -1 Then

ActiveDocument.Paragraphs(3).Range.Copy
Documents("REPORT.doc").Activate
Selection.MoveDown Unit:=wdParagraph, Count:=2
ActiveDocument.Range.Paste
ActiveDocument.Save

Documents("test.doc").Activate
Else
' MsgBox "The Check box is not checked"


End If

End Sub
Private Sub PARA3()

End Sub
 
Hi Buster,

Insert a bookmark where you want to paste.
Select that bookmark when you return and then:

oDoc.Content.Bookmarks.Item("test").Select()

oDoc.Content.Application.Selection.MoveRight(Unit:=CInt(Word.WdUnits.wdChara
cter), count:=2)
'do your paste


Let me know if this helps.
 
Don't forget to delete the bookmark when finished.
Then in your loop you can keep reusing it.
 
Buster said:
Here is the code.

Private Sub PARA1_Click()

If PARA1.Value = -1 Then
ActiveDocument.Paragraphs(1).Range.Copy
Documents.Add

Looks like Word VBA code. This here is a VB.NET ("dotnet", see group name)
group. Word VBA is handled at one of the microsoft.public.word.vba.* groups.
 
Hi Scorpion53061,

Thanks for your reply. Here is my code. I am pretty new
at this stuff so please bear with me. I am writing all of
this in Microsoft work using the visual basic editor.

Private Sub PARA1_Click()

If PARA1.Value = -1 Then
ActiveDocument.Paragraphs(1).Range.Copy
Documents.Add
ActiveDocument.SaveAs FileName:="C:\Documents and
Settings\jmielke\Desktop\REPORT.doc"
ActiveDocument.Range.Paste
Selection.MoveDown Unit:=wdParagraph, Count:=1

With ActiveDocument.Content
.InsertParagraphAfter
.InsertAfter Chr(10)
End With

Selection.MoveDown Unit:=wdLine, Count:=1

ActiveDocument.Save

Documents("test.doc").Activate

Else


End If

End Sub

Private Sub PARA2_Click()

If PARA2.Value = -1 Then

ActiveDocument.Paragraphs(3).Range.Copy
Documents("REPORT.doc").Activate
Selection.MoveDown Unit:=wdParagraph, Count:=2
ActiveDocument.Range.Paste
ActiveDocument.Save

Documents("test.doc").Activate
Else
' MsgBox "The Check box is not checked"


End If

End Sub
Private Sub PARA3()

End Sub


Regards,

Buster
 
Could you post what scorpions resonse to you was?

I may be able to help you.

I am concerned you are not in the correct ng however.
 
Hi Buster,

Insert a bookmark where you want to paste.
Select that bookmark when you return and then:

oDoc.Content.Bookmarks.Item("test").Select()

oDoc.Content.Application.Selection.MoveRight(Unit:=CInt
(Word.WdUnits.wdChara
cter), count:=2)
'do your paste


Let me know if this helps.
 
I am not really sure how I can create a bookmark
programtically, select it, use it and then delete it?
Sorry if I sound ignorant, but I am pretty new at this
stuff.

Regards,

Buster
 
On the destination document after your first paste is complete:

'untested......

With oDoc.Content.Application.ActiveDocument.Bookmarks
.Add(Range:=oDoc.Content.Application.Selection.Range,
Name:="testbookmark")
.DefaultSorting =
CInt(Word.WdBookmarkSortBy.wdSortByLocation)
.ShowHidden = True
End With

the next time you return to do another paste:

oDoc.Content.Bookmarks.Item("testbookmark").Select()

then we need to add a space in order to keep it readable:

oDoc.Content.Application.Selection.MoveRight(Unit:=CInt(Word.WdUnits.wdChara
cter), count:=2)

oDoc.Content.Bookmarks.Item("testbookmark").Delete()

oDoc.Content.Application.ActiveDocument.Activate 'not sure about this line


then do your next paste.

Let me know if you still have problems.

If you need to hire me I would entertain that thought as well :)
 
Thanks Peace!

I will give it a go and let you know how things work out.
If things go south, I might take you up on your offer of
hiring you for this project.

Buster
-----Original Message-----
 
Sounds good.


Thanks Peace!

I will give it a go and let you know how things work out.
If things go south, I might take you up on your offer of
hiring you for this project.

Buster
 
Peace said:
Sounds good.

Please note that it is not necessary to quote the same text again and again.
Just quote the paragraphs you are referring to. Thank you! It's a little
annoying for my to download the same quotes again and again several times.
Not only the unncessaray download, also scrolling and scrolling down just to
find...nothing. Please also see the links in my signature. These are only
guidlines no enforcements but they make sense. Thanks again!
 
Hi Peace,

You had mentioned that you are interested in doing some
work for me using visual basic. If you are still
interested, please email me at (e-mail address removed).

-Buster
-----Original Message-----
Sounds good.
 
Just so you know Peace and scorpion53061 are the same person.

:)

I ran into a little trouble on this group a while back ...
 
Back
Top