Create a word file from XL

  • Thread starter Sridhar Pentlavalli via OfficeKB.com
  • Start date
S

Sridhar Pentlavalli via OfficeKB.com

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
 
E

Ed

I changed your Dim statements as follows, and it works for me in Office
2000.
Dim appWD As New Word.Application
Dim docDoc As New Word.document
Dim rngRange As Word.Range
Make sure you have the Word object library selected.
Ed
 
S

Sridhar Pentlavalli via OfficeKB.com

Hi

Thank you very much for the help....

Thanks
Sridhar P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top