Creating a New Blank Word Document

The NewDoc function creates a new, blank Word document based on the default Word template:

Public Function NewDoc()

On Error GoTo ErrorHandler

Dim appWord As Word.Application Dim docs As Word.Documents Dim doc As Word.Document

Set appWord = GetObject(Class:="Word.Application";

Set docs = appWord.Documents docs.Add

Set doc = appWord.ActiveDocument

ErrorHandlerExit: Exit Function


If Err = 429 Then

'Word is not running; open Word with CreateObject Set appWord = CreateObject(Class:="Word.Application") Resume Next Else

& "; Description: " & Err.Description Resume ErrorHandlerExit End If

End Function

0 0

Post a comment