How to create word file

M

Mudit

Hi,
I want to create one word file from excel file, eg
if in one cell mention txt is Mudit , in other 29.....

i want out in .doc format - My Name is Mudit, I am 29 year old.

I mean to say it take data from xls and create one doc file.

i want to use VBA.....

I am novice for this.

Please help me

Mudit
 
G

Gordon

Mudit said:
Hi,
I want to create one word file from excel file, eg
if in one cell mention txt is Mudit , in other 29.....

i want out in .doc format - My Name is Mudit, I am 29 year old.

I mean to say it take data from xls and create one doc file.

i want to use VBA.....

I am novice for this.

Please help me

Mudit


Save the file as txt and then open in Word.......
 
M

movi1982

HI Mudit,

There are two ways u can achieve this, you can create an exce
macro...which opens a new word document and adds text in that exce
file in which macro is defined ... or you can create an applicatio
which will ask path for the excel file from which data is to b
taken...and creates a new document.I m giving here a word macro. creat
a new word document and go to VBE. paste the following code:

Sub AutoOpen()
'Enter File Path
x = InputBox("Enter the path of excel file" & Chr$(13) & Chr$(13) _
& "For example: C:\Customer.xls")'Enter file path
Call gen_doc(x)
End Sub
Function gen_doc(x)
Application.Documents.Add
ActiveDocument.ActiveWindow.View = wdPrintView
'Create an excel object
Set objExcel = CreateObject("Excel.Application")'first excel objec
has
'to be created
'open that particular excel document
Set xlWB = objExcel.Workbooks.Open(x)

On Error Resume Next

'open first sheet
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
objSheet.Visible = True
sname = objExcel.Cells(1, 1).Value
ActiveDocument.Select
Selection.TypeText Text:=sname

objSheet.Close False
xlWB.Close False ' close the workbook without saving
objExcel.Quit ' close the Excel application
Set objSheet = Nothing
Set xlWB = Nothing
Set objExcel = Nothing

End Function

and explore other possibilities.
Hope it helps :)
Movi1982
 
M

movi1982

HI Mudit,

There are two ways u can achieve this, you can create an exce
macro...which opens a new word document and adds text in that exce
file in which macro is defined ... or you can create an applicatio
which will ask path for the excel file from which data is to b
taken...and creates a new document.I m giving here a word macro. creat
a new word document and go to VBE. paste the following code:

Sub AutoOpen()
'Enter File Path
x = InputBox("Enter the path of excel file" & Chr$(13) & Chr$(13) _
& "For example: C:\Customer.xls")'Enter file path
Call gen_doc(x)
End Sub
Function gen_doc(x)
Application.Documents.Add
ActiveDocument.ActiveWindow.View = wdPrintView
'Create an excel object
Set objExcel = CreateObject("Excel.Application")'first excel objec
has
'to be created
'open that particular excel document
Set xlWB = objExcel.Workbooks.Open(x)

On Error Resume Next

'open first sheet
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
objSheet.Visible = True
sname = objExcel.Cells(1, 1).Value
ActiveDocument.Select
Selection.TypeText Text:=sname

objSheet.Close False
xlWB.Close False ' close the workbook without saving
objExcel.Quit ' close the Excel application
Set objSheet = Nothing
Set xlWB = Nothing
Set objExcel = Nothing

End Function

and explore other possibilities.
Hope it helps :)
Movi1982
 
M

movi1982

HI Mudit,

There are two ways u can achieve this, you can create an exce
macro...which opens a new word document and adds text in that exce
file in which macro is defined ... or you can create an applicatio
which will ask path for the excel file from which data is to b
taken...and creates a new document.I m giving here a word macro. creat
a new word document and go to VBE. paste the following code:

Sub AutoOpen()
'Enter File Path
x = InputBox("Enter the path of excel file" & Chr$(13) & Chr$(13) _
& "For example: C:\Customer.xls")'Enter file path
Call gen_doc(x)
End Sub
Function gen_doc(x)
Application.Documents.Add
ActiveDocument.ActiveWindow.View = wdPrintView
'Create an excel object
Set objExcel = CreateObject("Excel.Application")'first excel objec
has
'to be created
'open that particular excel document
Set xlWB = objExcel.Workbooks.Open(x)

On Error Resume Next

'open first sheet
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
objSheet.Visible = True
sname = objExcel.Cells(1, 1).Value
ActiveDocument.Select
Selection.TypeText Text:=sname

objSheet.Close False
xlWB.Close False ' close the workbook without saving
objExcel.Quit ' close the Excel application
Set objSheet = Nothing
Set xlWB = Nothing
Set objExcel = Nothing

End Function

and explore other possibilities.
Hope it helps :)
Movi1982
 
M

movi1982

HI Mudit,

There are two ways u can achieve this, you can create an exce
macro...which opens a new word document and adds text in that exce
file in which macro is defined ... or you can create an applicatio
which will ask path for the excel file from which data is to b
taken...and creates a new document.I m giving here a word macro. creat
a new word document and go to VBE. paste the following code:

Sub AutoOpen()
'Enter File Path
x = InputBox("Enter the path of excel file" & Chr$(13) & Chr$(13) _
& "For example: C:\Customer.xls")'Enter file path
Call gen_doc(x)
End Sub
Function gen_doc(x)
Application.Documents.Add
ActiveDocument.ActiveWindow.View = wdPrintView
'Create an excel object
Set objExcel = CreateObject("Excel.Application")'first excel objec
has
'to be created
'open that particular excel document
Set xlWB = objExcel.Workbooks.Open(x)

On Error Resume Next

'open first sheet
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
objSheet.Visible = True
sname = objExcel.Cells(1, 1).Value
ActiveDocument.Select
Selection.TypeText Text:=sname

objSheet.Close False
xlWB.Close False ' close the workbook without saving
objExcel.Quit ' close the Excel application
Set objSheet = Nothing
Set xlWB = Nothing
Set objExcel = Nothing

End Function

and explore other possibilities.
Hope it helps :)
Movi1982
 
Top