Try this Code to create a Word File:
Code:
Public Sub CreateWordDoc()
Dim WordObj As Object, wrkSheet As Worksheet
Dim Rng As Range, wrdFileName As String
On Error GoTo CreateWordDoc_Err
Set wrkSheet = ActiveWorkbook.Worksheets("Sheet1")
With wrkSheet
wrdFileName = .Range("A1").Value
End With
Set WordObj = CreateObject("word.application")
WordObj.Application.Visible = True
WordObj.Application.Documents.Add "Normal", , 0, True
WordObj.ActiveDocument.Content = "THIS IS MY TEST DOCUMENT."
WordObj.Application.ActiveDocument.SaveAs "C:\" & wrdFileName & ".doc"
WordObj.Application.Quit
Set WordObj = Nothing
CreateWordDoc_Exit:
Exit Sub
CreateWordDoc_Err:
MsgBox Err.Description, , "CreateWordDoc"
Resume CreateWordDoc_Exit
End Sub
- Copy and Paste the above Code into a Standard Module of Excel.
- Enter the required File Name in Cell A1.
- Place the insertion point in the middle of the Code and press F5.