#1
|
|||
|
|||
How to link userform to another word document
Hello
I have created a userform which will be used by various people. The userform contains fields which the user will fill in to create DocVariables which are contained in the word document behind the form. This all works fine. However, I want the userform to populate various letters. The user will click on a command button which will find and open various letter templates which are populated with DocVariable fields. The problem is, when the userform opens these letters the docvariables are not populating and I get the 'Error! No document variable supplied.' message. I somehow need to get the letter that the userform opens to look at the userform variables and populate the active links with those variables, but try as I might I have no been able to figure out how to do it. Any help would be much appreciated. Thanks. |
#2
|
||||
|
||||
Hi SaneMan,
Without seeing a document with your userform code, plus a sample target document, it's hard to say what the issue is. There are various possibilities.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Quote:
If you open the form and go to the second tab you can input some details and then the letter is in the third tab. If you want to get behind the form to look at the macros you click on the big button on the first tab. I've set the letter to open from My Documents so you might need to change the route address if you want to try it out. Really struggling to get the letter it opens to populate from the variables from the form! Thanks so much for the help. |
#4
|
||||
|
||||
Hi SaneMan,
If you run the following code, you'll see which variables do/don't exist. It's a bit hard to populate those that don't ... Code:
Sub Test() Dim i With ActiveDocument For i = 1 To .Variables.Count MsgBox .Variables(i).Name & vbCr & .Variables(i).Value Next End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Quote:
Thanks for that. I tested the Macro on the userform and all the variables that I have entered appear to be populating. If I put a letter into the actual document behind the userform then the variables populate fine. The problem appears to occur when the form opens the letter up from another location. It opens it up fine but there doesn't seem to be a link between the userform and the new document that would communicate with it and input the variables into the DocVariable references in the letter. I feel like there must be an obvious and simple way of fixing this but I've ran out of ideas. I assume there must be some code you can put into the macros in the user form so that when the form opens up the new letter it has a direct link to it and refreshes the variables in the letter with the variables that have already been populated on the form. Thanks for your help on this. |
#6
|
||||
|
||||
Hi SaneMan,
If you compared the output from the macro I posted to the DocVariables you're trying to work with, you'd see that none of them exist! It's not a matter of what's on the userform, it's a matter of what DocVariables exit in the underlying document. Whatever document you're running the code against needs to have the DocVariables in it too - and, presumably, you'll need to create them if they don't.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Word doc bug when closing from userform command button click macro | Joe Patrick | Word | 1 | 07-05-2011 08:53 PM |
Setting focus to specific word document from UserForm | SaneMan | Word VBA | 5 | 04-01-2011 03:11 PM |
Checkbox on Userform result in Text in Word | Dolfie_twee | Word VBA | 1 | 06-22-2010 07:54 AM |
[Word 2003] Macro's and a UserForm | xanuex | Word VBA | 0 | 10-19-2009 05:42 AM |
How to link text from one document to another | nospamforyou | Word | 0 | 10-09-2008 09:14 AM |