Insert a selection at the end of a Word Document

R

RoVo

Hello,
I am creating a userform that takes a string and adds it to the end
of a different word file. For example, the current file has a text
string inputted from the user via the form, and I need to take that
string, then transfer it over to a existing file that already has text
in it and paste it at the end. Any help would be appreciated.

Rob
 
J

Jean-Guy Marcil

RoVo was telling us:
RoVo nous racontait que :
Hello,
I am creating a userform that takes a string and adds it to the end
of a different word file. For example, the current file has a text
string inputted from the user via the form, and I need to take that
string, then transfer it over to a existing file that already has text
in it and paste it at the end. Any help would be appreciated.

Play around with this:

Dim strText As String
Dim docTarget As Document
Dim rgeDocTarget As Range

strText = "This String!"

Set docTarget = Documents.Open("C:\Your_Path\Document_Name.doc")
With docTarget
Set rgeDocTarget = .Range
rgeDocTarget.InsertAfter strText
.Close wdSaveChanges
End With


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
G

Greg Maxey

Rob,

Put something like the following in your command button code:

Private Sub CommandButton1_Click()
Dim myFile As Word.Document
Set myFile = Documents.Open(FileName:="C:\Test.doc")
With myFile
.Range.InsertAfter Me.TxtBox1 '(the textbox that holds the users
string input)
.Close SaveChanges:=wdPromptToSaveChanges
End With
Unload Me
End Sub
 

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