View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Macro for Creating Word Document!!

Hi Akash,

Am Mon, 4 Mar 2013 09:33:16 -0800 (PST) schrieb Akash:

A1 Akash,
A2 Rohit,
A3 Rakesh
A4 Amit

Column B - It has got contents having Text.

B1 bbbbbbbbbbbbbbbbbb
B2 cccccccccccccccccc
B3 dddddddddddddddddd
B4 eeeeeeeeeeeeeeeeee

What is required is a macro. As soon as we run a Macro, Word document
gets generated Named as Akash.doc and it should have text which is in
Column B1. E.g.


try:

Sub ExportToWord()
Dim objWord As Object
Dim LRow As Long
Dim rngC As Range
Dim myPath As String

Set objWord = CreateObject("Word.application")
myPath = "C:\Users\Akash Maheshwari\Desktop\"

LRow = Cells(Rows.Count, 1).End(xlUp).Row
For Each rngC In Range("A1:A" & LRow)
With objWord
.Visible = True
.Activate
.documents.Add
.Selection.Text = rngC.Offset(0, 1)
.activedocument.SaveAs Filename:=myPath & rngC & ".docx"
.activedocument.Close
End With
Next
Set objWord = Nothing
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2