Microsoft Office Tutorials and References
In Depth Information
Creating a New Word Document
‘The document is open, so activate it.
‘Release the system memory that was reserved for the two
‘Object variables.
Set wddoc = Nothing
Set WdApp = Nothing
End Sub
crEATing A nEW Word docuMEnT
You can easily create a new Word document from scratch with the statement
You’ll typically create a new Word document for the purpose of holding some kind of narrative or
data, which means you’ll want to save your new document. Tapping into many of the same
processes that were covered in the ActivateWord macro, here is an example of a macro that creates and
saves a new Word document:
Sub CreateWordDoc()
‘Declare Object variables for the Word application
‘and new document.
Dim objWordApp As Object, objWordDoc As Object
‘On Error statement if Word is not already open.
On Error Resume Next
‘Activate Word if it is already open.
Set objWordApp = GetObject(, “Word.Application”)
If Err.Number = 429 Then
‘Create a Word application if Word is not already open.
Set objWordApp = CreateObject(“Word.Application”)
End If
‘Make sure the Word application is visible.
objWordApp.Visible = True
‘Activate the Word application.
‘Create your new Word document.
Set objWordDoc = objWordApp.Documents.Add
‘Save your new Word document in a folder path.
objWordDoc.SaveAs “C:\Your\File\Path\myNewWordDoc.docx”
‘Release the system memory that was reserved for the
‘two Object variables.
Set objWordApp = Nothing
Set objWordDoc = Nothing
End Sub
Search JabSto ::

Custom Search