LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Excel Macro to Auto-Populate a Word Template

Here is one, you'll have to wade through and use what is relevant to your
needs... this shows both manual population of two bookmarks, and also
populating a series of bookmarks by looping through an array.
HTH
Keith

Sub MakeGuideA()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
Dim BMRange As Word.Range
Dim toc As Word.TableOfContents

wrdApp.Visible = True
wrdApp.DisplayAlerts = wdAlertsNone

Set wrdDoc = wrdApp.Documents.Open(CurrentPath & "Interview_GuideA" &
".doc", , True)

'word operations
With wrdDoc
For deleteComp = 1 To 18
Bkmksize = .Bookmarks.Count

thisVal = Application.WorksheetFunction.Max(WordArray)
thismatch = Application.Match(thisVal, WordArray, 0)
If IsError(thismatch) Then
Exit For
Else
BookMarkName = .Bookmarks(thisVal).Name
If thisVal 0 Then
Set BMRange = wrdDoc.Bookmarks(BookMarkName).Range
BMRange.Text = ""
.Bookmarks.Add BookMarkName, BMRange
End If
WordArray(thismatch) = ""
End If
Next

BookMarkName = .Bookmarks(2).Name
Set BMRange = wrdDoc.Bookmarks(BookMarkName).Range
BMRange.Text = ApplicantName
.Bookmarks.Add BookMarkName, BMRange

BookMarkName = .Bookmarks(17).Name
Set BMRange = wrdDoc.Bookmarks(BookMarkName).Range
BMRange.Text = PositionString
.Bookmarks.Add BookMarkName, BMRange

For Each toc In wrdDoc.TablesOfContents
toc.Update
Next

wrdDoc.SaveAs (CurrentPath & ApplicantName & ".doc")
.Close ' close the document
End With

wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub


"Dan Thorman" wrote in message
...
This seems like the way to go. So, seeing as how new I am to all of this,
I
have been looking for some code examples of how to iterate through the
bookmarks in the template i have created and populate them with cells from
the Excel spreadsheet. Unfortunately, I cannot seem to find any such
examples. Does anybody happen to know of any?

P.S. Thanks for your help Ed!

"Ed" wrote:

Dan: If the data is the same data points each time, just different data,
then create a template in Word (a Word doc saved as ".dot") that has all
of
your data point locations as bookmarks. In your Excel macro, set an
object
to Word and open a new doc based on that template (see
http://word.mvps.org/FAQs/InterDev/C...ordFromXL.htm). Then iterate
through the document's Bookmarks collection and set your data into each
bookmark, then SaveAs with your doc name.

HTH
Ed

"Dan Thorman" wrote in message
...
I am using Excel to pull data together from multiple sources, and am
trying
to set it up as, essentially, a dashboard for a user. I have it set so
that
the user hits a button and all the data that they need is automatically
pulled in to the workbook. However, I have a MS Word form that I would
like
the data to be pushed to, and I cannot figure out how to write the
macro
to
automatically populate that particular form. I would normally just
write
the
macro so that it created the document from scratch every time, but
there
is a
LOT of static data in the form, and it changes often.

I am using Excel 2003

Can anyone provide an example of the code for how to do this? I am
very
new
to VBA programming (and not a programmer by trade), so an example
should
allow me to figure out how to make it work in this particular instance.

Thanks in advance for all your help!






 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excell auto-populate word? LUCHA Excel Worksheet Functions 2 November 3rd 09 01:05 PM
How can I have Excel cells populate a Word label template? MS Questionnairess Excel Discussion (Misc queries) 1 June 8th 06 01:26 AM
Enable Word Template Macro from Excel L Smith Excel Programming 1 October 29th 05 09:15 AM
export excel data to a word template using a macro Ross1 Excel Programming 1 March 25th 05 04:31 AM
How to auto increment a template in Excel & Word talldow Excel Programming 1 January 22nd 05 06:59 AM


All times are GMT +1. The time now is 06:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"