View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sridhar Pentlavalli via OfficeKB.com[_2_] Sridhar Pentlavalli via OfficeKB.com[_2_] is offline
external usenet poster
 
Posts: 1
Default Create a word file from XL

Hi

I have an XL sheet with employee name and salary details. I need to create
salary certificate for the employee in word file and store it in desktop.
The following is the code I used for achieving it but gives problem in the
line "Set rngRange = docDoc.Range". Says "Type mismatch - Run time error
13". I am running this code from XL.

Anybody please help....

Thanks in advance
Sridhar P


Sub Word_File()

Dim appWD As Object
Dim docDoc As Object
Dim rngRange As Range

' Create a new instance of Word & make it visible
Set appWD = CreateObject("Word.Application.10")
appWD.Visible = True

emp_name = Worksheets("Data").Cells(1, 1).Value
emp_sal = Worksheets("Data").Cells(1, 2).Value

' Tell Word to create a new document
Set docDoc = appWD.Documents.Add

' Position your range object (insertion point)
' For example, this sets the insertion point at the beginning of the
document

Set rngRange = docDoc.Range
rngRange.Collapse wdCollapseStart

' Tell Word to paste the contents of the clipboard into the new document

text0 = " SALARY CERTIFICATE "
text1 = " ==================== "
text2 = " This is to certify that MR." & emp_name
text3 = " was entitled to receive a salary of " & emp_sal
text4 = " per month "

rngRange.Text = text0 & vbNewLine & _
text1 & _
text2 & _
text3 & _
text4

' Tell Word to paste the contents of the clipboard into the new document
' appWD.Selection.Paste

' Save the new document with a sequential file name
appWD.ActiveDocument.SaveAs "C:\Documents and Settings\" & user_id & "\
Desktop\" & fil_nam & ".doc"

' Select the Data sheet
Sheets("Data").Select

' Close this new word document
appWD.ActiveDocument.Close

' Close the Word application
appWD.Quit

MsgBox " Please look on your desktop for a WORD file ... "

End Sub

--
Message posted via http://www.officekb.com