Article ID: 132003
Article Last Modified on 10/11/2006
Name: MyOle
ControlSource: MyOle
Sub CopyDocument_Click ()
Dim NewObject As Object
Dim NewDoc As String
Dim DocPath As String
' Name of the new document to create.
NewDoc = "TEST.DOC"
' 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 = Me!MyOle.Object.Application.WordBasic.DefaultDir(9)
' Copies the embedded object to Clipboard.
Me!MyOle.Verb = 0
Me!MyOle.Action = 7
Me!MyOle.Object.Application.WordBasic.EditSelectAll
Me!MyOle.Object.Application.WordBasic.EditCopy
Me!MyOle.Action = 9
DoEvents
' 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
' Frees the memory used by the objects.
Set NewObject = Nothing
MsgBox DocPath & "\" & NewDoc & " was created successfully."
End Sub
Option ExplicitKeywords: kbhowto kbprogramming KB132003