Generating Word 2000 data from an Excel VBA program : Word Document « Word « VBA / Excel / Access / Word






Generating Word 2000 data from an Excel VBA program

 
Sub MakeMemos()
    Dim WordApp As Object
    Set WordApp = CreateObject("Word.Application")
    
    For i = 1 To 3
        Application.StatusBar = "Processing Record " & i

        SaveAsName = ThisWorkbook.Path & "\test.doc"

        With WordApp
            .Documents.Add
            With .Selection
                .Font.Size = 14
                .Font.Bold = True
                .ParagraphFormat.Alignment = 1
                .TypeText Text:="M E M O R A N D U M"
                .TypeParagraph
                .TypeParagraph
                .Font.Size = 12
                .ParagraphFormat.Alignment = 0
                .Font.Bold = False
                .TypeText Text:="Date:" & vbTab & Format(Date, "mmmm d, yyyy")
                .TypeParagraph
                .TypeText Text:="To:" & vbTab & " Manager"
                .TypeParagraph
                .TypeText Text:="From:" & vbTab & _
                   Application.userName
                .TypeParagraph
                .TypeParagraph
                .TypeText "text"
                .TypeParagraph
                .TypeParagraph
                .TypeText Text:="Units Sold:" & vbTab & "asdf"
                .TypeParagraph
                .TypeText Text:="Amount:" & vbTab & Format(1000, "$#,##0")
            End With
                .ActiveDocument.SaveAs FileName:=SaveAsName
                .ActiveWindow.Close
        End With
    Next i
    WordApp.Quit
    Set WordApp = Nothing
    Application.StatusBar = ""
    MsgBox " memos were created and saved in " & ThisWorkbook.Path
End Sub

 








Related examples in the same category

1.Add a word document
2.To create a new document that uses a specific template, use this:
3.Open an Existing Document
4.Save Changes to a Document
5.To save a document with a new name, use the SaveAs method
6.To close a specific document, you can close the active document or you can specify a document name:
7.Save a document
8.Load contact table from Access and create letter in Word
9.Close a document