INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

VBA Visual Basic for Applications (Microsoft) FAQ

Microsoft Word How To?

How quickly can i update data in a word document by Chance1234
Posted: 13 Dec 05

Possibly the Quickest way to populate data in a word document.

Where you want to insert the data in a word document, use insert bookmarks.

Give all the bookmarks the same name and then add a incremement number to the end,
so for example

test1
test2
test3
test4
test5


Then in your code you can create a loop , to simply move through the bookmarks, for example


CODE

Sub subPopulatedocument
Dim str_bk as string
Dim int_cnt as integer

int_cnt = 1

do until int_cnt = 5
      str_bk = "TEST" & int_cnt
      ActiveDocument.Bookmarks(str_bk).Range.Text = "hello world"
      int_cnt = int_cnt + 1
loop

end sub

Note the above will put hello world at all the documents, to insert data, if its data generated in the code, then the above code would be

CODE


Sub subPopulatedocument
Dim str_bk as string
Dim int_cnt as integer
Dim str_file(5) as string

str_file(1) = "First bit of data"
str_file(2) = "Third bit of data"
str_file(4) = "fourth bit of data"
str_file(5) = "fifth bit of data"

int_cnt = 1

do until int_cnt = 5
      str_bk = "TEST" & int_cnt
          ActiveDocument.Bookmarks(str_bk).Range.Text = str_file(int_cnt)
      int_cnt = int_cnt + 1
loop

end sub

If i was transfering data from a excel spreadsheet or access database, then i would throw the data into array and manage that array so it would fit in with the above code.

Back to VBA Visual Basic for Applications (Microsoft) FAQ Index
Back to VBA Visual Basic for Applications (Microsoft) Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close