rockdrigotoca
New Member
- Joined
- Aug 24, 2010
- Messages
- 23
Hi there!!
I am trying to create word documents from the cells I have in Excel. So far I have managed to create 1! But what if I have more than one data on Excel??
On Excel, Sheet1 I have row 1 as Titles for Address_Name, Address1, Address2, Letter_Date, Salutation, Owed_Amount. I have the same in a word document marked as bookmarks. So the macro already sends that info but just for Row2.
Could you please help me if I need to extend that macro to all rows from Excel? The number of letters (and data) may vary.
Please help!!
The code is:
I am trying to create word documents from the cells I have in Excel. So far I have managed to create 1! But what if I have more than one data on Excel??
On Excel, Sheet1 I have row 1 as Titles for Address_Name, Address1, Address2, Letter_Date, Salutation, Owed_Amount. I have the same in a word document marked as bookmarks. So the macro already sends that info but just for Row2.
Could you please help me if I need to extend that macro to all rows from Excel? The number of letters (and data) may vary.
Please help!!
The code is:
PHP:
Option Explicit
Sub ExcelCells_to_Word()
Dim WdApp As Object, wd As Object, ac As Long, ws As Worksheet
Dim wsData As Worksheet
Dim wsControl As Worksheet
Set ws = Worksheets("Sheet1")
Set WdApp = CreateObject("Word.Application")
Set wd = WdApp.Documents.Open("C:\Debt Recovery Letters\Word Template\TestLetter.doc")
WdApp.Visible = True
Dim rng1 As Range
Dim m As Long
m = Range("A" & Rows.Count).End(xlUp).Row
Range("A2:A" & m).Select
Set rng1 = wsData.Range(Cells(2, 1), Cells(Rows.Count, 1).End(xlUp))
' I am not sure if this is the way to go to create the loop, please help!!
For Each rng1 In Worksheets("Sheet1")
With wd.Bookmarks
.Item("Address_Name").Range.InsertAfter Worksheets("Sheet1").Range("A2").Value
.Item("Address1").Range.InsertAfter Worksheets("Sheet1").Range("B2").Value
.Item("Address2").Range.InsertAfter Worksheets("Sheet1").Range("C2").Value
.Item("Letter_Date").Range.InsertAfter Worksheets("Sheet1").Range("D2").Value
.Item("Salutation").Range.InsertAfter Worksheets("Sheet1").Range("E2").Value
.Item("Owed_Amount").Range.InsertAfter Worksheets("Sheet1").Range("F2").Value
End With
Next rng1