Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
create hyperlink from exel file to particular word in word file Hiten Kapasi Excel Discussion (Misc queries) 1 May 15th 10 11:58 AM
How to create word file Mudit Excel Discussion (Misc queries) 5 July 18th 06 11:00 AM
Any way to create an Excel file from data in Word? putty Excel Discussion (Misc queries) 1 June 19th 06 07:50 PM
Automation: Create Word file from Excel Steve C.[_2_] Excel Programming 0 March 31st 05 02:23 PM
How to I create a pdf file from Word or Excel files stolitx Excel Discussion (Misc queries) 4 December 28th 04 07:17 PM


All times are GMT +1. The time now is 01:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"