Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create a word file from XL
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 "Sridhar Pentlavalli via OfficeKB.com" wrote in message ... 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create a word file from XL
Hi
Thank you very much for the help.... Thanks Sridhar P -- Message posted via http://www.officekb.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
create hyperlink from exel file to particular word in word file | Excel Discussion (Misc queries) | |||
How to create word file | Excel Discussion (Misc queries) | |||
Any way to create an Excel file from data in Word? | Excel Discussion (Misc queries) | |||
Automation: Create Word file from Excel | Excel Programming | |||
How to I create a pdf file from Word or Excel files | Excel Discussion (Misc queries) |