Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How quickly can i update data in a word document

Microsoft Word How To?

How quickly can i update data in a word document

by  Chance1234  Posted    (Edited  )
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.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top