Microsoft Office Tutorials and References
In Depth Information
Set appWord = GetObject(, "Word.Application”)
appWord.Visible = True
appWord.Activate
Set doc = appWord.ActiveDocument
appWord.ShowMe
With doc
doc.Activate
doc.Application.Selection.TypeText "This file was created " & Date
End With
End Sub
Creating a New Word Document
There will be times when you want to create a new file instead of working with an existing
Word document. To accomplish this task, you need to have an open instance of Word and
then you’ll create a new document.
The following example uses early binding, so the code to create a new document is the same
as if you were creating a new document from Word. Before you test this procedure, add the
Word Object Library to your procedure.
Sub CopyFromExcelToNewWordDocument()
Dim wdApp As Word.Application
ThisWorkbook.Sheets("Table”).Range("A1:B6”).Copy
On Error Resume Next
Set wdApp = GetObject(, "Word.Application”)
If wdApp Is Nothing Then
Set wdApp = GetObject("", "Word.Application”)
End If
On Error GoTo 0
With wdApp
.Documents.Add
.Visible = True
End With
With wdApp.Selection
.EndKey unit:=wdStory
.TypeParagraph
.Paste
End With
Set wdApp = Nothing
End Sub
Search JabSto ::




Custom Search