Macro for Creating Word Document!!
On Mar 4, 11:02*pm, Claus Busch wrote:
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
Moreover, Its transferring the Tex of first cell but not naming the
file
After the first run its giving Runtime Error.
Pls help in closing the same.
Awaiting for your responses regarding the same.
Rgds
Akash Maheshwari
|