Populate MS Word table via VBA?
Posted on 2010-09-16
I have some Word documents which have a small table in them. I don't know much, if anything, able tables in Word. The document itself serves as a mechanism to print labels, 4 labels to a page, i.e. it is a full page with 4 labels on it.
The table is structured so that 2 cells fall on each of the 4 labels. These cells are currently manually updated with the Lot # and Expiration date that are on the labels.
When a user opens the document, it is mostly protected so they can't change anything, but they can enter data into the cells of the table. So a user would open the document and for each of the four labels the user will update the cell that has the Lot # and the cell that has the Exp. date. Naturally, the completely manual system results no and then in errors, entering a lot # 4 times sometimes results in an incorrect lot # in one of the cells (and hence one of the labels).
What I would like to do is prompt the use to enter the lot # once and the expiration date once and then update all the cells via VBA.
I have this so far:
Private Sub Document_Open()
Dim UseBy As String
Dim Lot As String
UseBy = InputBox("Please enter the Use By date in YY-MMM-DD format", "UseBy Date")
Lot = InputBox("Please enter the Lot in DF-YY-### format", "Lot #")
The question I have is "Now what?".
Thanks in advance.