If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Mail Merge

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-21-11, 15:17
PJones1 PJones1 is offline
Registered User
 
Join Date: Jul 2011
Posts: 1
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.
Reply With Quote
  #2 (permalink)  
Old 07-25-11, 10:30
apr pillai apr pillai is offline
Registered User
 
Join Date: Jan 2009
Location: Kerala, India
Posts: 107
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
  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.
__________________
http://www.msaccesstips.com (Learn MS-Access Tips & Tricks)
Learn Advanced MS-Access Programming with sample VBA Code.
Reply With Quote
Reply

Tags
mailmerge

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On