Copy and paste into word from access

P

Paul McC

Hi all,


It's a little late in the day for me so please forgive as i need my bed.!!


The issue is i need to open a word doc (say "c:\temp.doc) and paste into it,
but i only can work out how to open a NEW doc


' Creates a new document and pastes Clipboard contents.
' Saves the document in the Word directory and closes the
' document.

Set NewObject = CreateObject("Word.Basic")
NewObject.filenew
NewObject.editpaste
NewObject.filesaveas DocPath & "\" & NewDoc
NewObject.FileClose
 
P

PieterLinden via AccessMonster.com

Paul said:
Hi all,

It's a little late in the day for me so please forgive as i need my bed.!!

The issue is i need to open a word doc (say "c:\temp.doc) and paste into it,
but i only can work out how to open a NEW doc

' Creates a new document and pastes Clipboard contents.
' Saves the document in the Word directory and closes the
' document.

Set NewObject = CreateObject("Word.Basic")
NewObject.filenew
NewObject.editpaste
NewObject.filesaveas DocPath & "\" & NewDoc
NewObject.FileClose

More information please. What are you pasting into Word? Records from a
query? If so, open an ADO recordset, convert it to a delimited string using
GetString, then pass the string to Word, and format there.
 
P

Paul McC

Hi all,


i have it sorted out now, i was coping from an Bound OLE Oject on a form to
a word template.

F.Y.I here 's the code


Private Sub Command31_Click()

Dim NewObject As Object
Dim NewDoc As String
Dim DocPath As String

' Name of the new document to create.
Dim Dnam As String
Dnam = Me.Text32 & ".doc"
NewDoc = Dnam

' Where to store the new document.
' DefaultDir$(9) returns the Word directory path.
' See DefaultDir$() in Word's on-line help for more options.
' Note: The "$" is not used when calling DefaultDir via
' OLE Automation.
DocPath = "D:\Kpic"

' Copies the embedded object to Clipboard.
Me!Photograph.Verb = 0
Me!Photograph.Action = 7
Me!Photograph.Object.Application.WordBasic.EditSelectAll
Me!Photograph.Object.Application.WordBasic.EditCopy
Me!Photograph.Action = 9
DoEvents


' Opens a word template document and pastes Clipboard contents.
' Saves to a new file and document in the Word directory and
closes the
' document.

Set NewObject = CreateObject("Word.Application")
NewObject.Visible = True
NewObject.Activate
NewObject.ChangeFileOpenDirectory "D:\"
NewObject.Documents.Open FileName:="Point.dotx"
NewObject.Selection.Paste
'removes an extra space!
NewObject.Selection.TypeBackspace

NewObject.ActiveDocument.SaveAs FileName:=DocPath & "\" & NewDoc

NewObject.ActiveDocument.Close

' Frees the memory used by the objects.
Set NewObject = Nothing

MsgBox DocPath & "\" & NewDoc & " was created successfully."
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