PDA

View Full Version : Word Template - Table cell reference



DomFino
11-18-2004, 10:19 AM
Hi everyone,
I have a word 2000 template that contains a table. The cell C3, in this case contains text that I want to reference and have it display in another part of the same form. The problem is the table is filled by a macro that allows the user to select a name and address from the Outlook Contacts. Once the user selects a contact the information displays in cell C3 of the table. This same data needs to display at the end of the form but I cannot figure out how to capture the text data in cell C3 of the table and have it display at the end of the template.

I tried to bookmark the cell but that did not work. Any suggestions? :dunno

TonyJollans
11-18-2004, 07:07 PM
Well, if the table is filled by a macro, then the macro should be able to use the same source data and put it in two places - you shouldn't need to capture it, you must already have it.

DomFino
11-19-2004, 06:32 AM
Tony,
Thanks for your reply. I don't know what I was thinking. As soon as I read your reply I took a look at the code behind the template (see below). The code in bold inserts the information at the insertion point but how do I also get it to insert the information an another field? Do I create another field and say it =strAddress?




Public Sub InsertAddressFromOutlook()
Dim strCode As String, strAddress As String
Dim iDoubleCR As Integer
'Set up the formatting codes in strCode
strCode = "<PR_DISPLAY_NAME>" & vbCr & _
"<PR_POSTAL_ADDRESS>" & vbCr & _
"<PR_OFFICE_TELEPHONE_NUMBER>" & vbCr


'Display the 'Select Name' dialog, which lets the user choose
'a name from their Outlook address book
strAddress = Application.GetAddress(AddressProperties:=strCode, _
UseAutoText:=False, DisplaySelectDialog:=1, _
RecentAddressesChoice:=True, UpdateRecentAddresses:=True)
'If user cancelled out of 'Select Name' dialog, quit
If strAddress = "" Then Exit Sub
'Eliminate blank paragraphs by looking for two carriage returns in a row
iDoubleCR = InStr(strAddress, vbCr & vbCr)
Do While iDoubleCR <> 0
strAddress = Left(strAddress, iDoubleCR - 1) & _
Mid(strAddress, iDoubleCR + 1)
iDoubleCR = InStr(strAddress, vbCr & vbCr)
Loop
'Strip off final paragraph mark
strAddress = Left(strAddress, Len(strAddress) - 1)
'Insert the modified address at the current insertion point

Selection.Range.Text = strAddress

End Sub

Jacob Hilderbrand
11-19-2004, 06:37 AM
Change your insertion pioint to the new spot and then run this line again.
Selection.Range.Text = strAddress

DomFino
11-19-2004, 06:44 AM
Jacob,
When you say, "change your insertion point", do you mean in the code? How? Sorry, if I sound stupid on this, but I really don't know much about VbA. To be honest, I was thrilled that the first part worked the way it was supposed to.

Jacob Hilderbrand
11-19-2004, 06:55 AM
Yes, change the insertion point in the code then put the value in the new spot. For example:

Selection.Range.Text = "Test"
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.Range.Text = "Test"
Selection.GoTo What:=wdGoToBookmark, Name:="MyBookMark"
Selection.Range.Text = "Test"

You can use MoveDown (or Up) to go to new lines or you can go to a specific Book Mark.

DomFino
11-19-2004, 08:41 AM
Tony,
You are the man. The code worked like a charm. It's easy when you know how, I guess.
Thank you so much for your help.
Dom

DomFino
11-19-2004, 07:12 PM
Sorry, I ment to address the previous message to Jacob.