Excel Range to Word Template using VBA
Most often we maintain list of contacts in Excel workbook and it needs to be transferred to Word document (made from some template). Here is a simple snippet that can help:
The code is used to copy the content from Excel range shown below to a Word document:
Sub CopY_Data_To_Word()
Dim oWA As Word.Application
Dim oWD As Word.Document
Set oWA = New Word.Application
Set oWD = oWA.Documents.Add("C:\Users\comp\Documents\Doc2.dot") ' Replace with your template here
For i1 = 2 To Cells.SpecialCells(xlCellTypeLastCell).Row
oWD.Bookmarks("Name").Range.Text = Cells(i1, 1)
oWD.Bookmarks("ContactNo").Range.Text = Cells(i1, 2)
oWD.Bookmarks("Address").Range.Text = Cells(i1, 3)
oWD.Bookmarks("Email").Range.Text = Cells(i1, 4)
'Code for saving the document
Next i1
' Releasing objects etc
End Sub
Bookmarks are added to the Word template and whenever a new document is created from the template, the document has those bookmarks.
The code above places the information from the Excel sheet to the specific Bookmark ranges
Code/Templates/Informaiton provided on this site are without any liabilities. Owner of this website in no event will be held reponsible to damages resulting by using the code/templates/applications/
Copyright © 2003 xlMacros.com - Learn Excel VBA
Microsoft Excel is a U.S. registered trademark of Microsoft Corporation
Excel Password Cracker Addin.
For $10 Today. Price back to $20 tommorow.
Never Worry About Lost Excel Passwords!!!
Remove Excel Password - the easy way has never been easier than this.