Results 1 to 2 of 2

Thread: Mail Merge

  1. #1
    Join Date
    Jul 2011

    Unanswered: Mail Merge

    Hi I'm new to this forum.

    Need some direction on the best approach to create a file (name using the content of a cell) using excel/vba. Any help would be great.

  2. #2
    Join Date
    Jan 2009
    Kerala, India
    Try this Code to create a Word File:
    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"
    Set WordObj = Nothing
    Exit Sub
    MsgBox Err.Description, , "CreateWordDoc"
    Resume CreateWordDoc_Exit
    End Sub
    1. Copy and Paste the above Code into a Standard Module of Excel.
    2. Enter the required File Name in Cell A1.
    3. Place the insertion point in the middle of the Code and press F5. (Learn MS-Access Tips & Tricks)
    Learn Advanced MS-Access Programming with sample VBA Code.

    All responses are based on Access 2003/2007

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts