![]() |
|
|
|
#1
|
|||
|
|||
|
I figured it out!! S
Private Sub PrintBlurb2_Click() ' Declare everything strings. Dim EVParty, EVNum, arr() As String ' Pull the values from the Userform text boxes of PartyTypeList and EvidenceID. EVParty = PartyTypeList.Value EVNum = EvidenceID.Value 'Create a simple array of one item that pushed the two items together into one item. arr = Split("EVParty&EVNum| EVPartyEVNum", "|") 'Use the array zero point to create a variable with an out put that is the same as the name of the variable, but with a space in it. ActiveDocument.Variables(arr(0)) = EVParty & " " & EVNum ' Make a message box that does the check. MsgBox ActiveDocument.Variables(arr(0)) Unload Me End Sub |
|
#2
|
||||
|
||||
|
I'm not convinced you have this solved yet. Your current code actually populates the same variable (called "EVParty&EVNum") regardless of the actual values in your variables.
You have variables but are using strings of the variable names and expecting the macro to convert the string name of the variable into the variable value. Also, using a space as a separator is useless if either of the variable values contain a space - better to use something that won't appear in the values such as "|" If you are intending to create a variable based on the values entered by the user in the userform, how are you going to make use of it in the document and/or when reopening the userform? You won't know the name of the variable to go looking for it. I would recommend a unique location/name for this data location and if you need to store multiple values there then make them all part of a single string with a separator. For example to write the form info to a variable Code:
EVParty = PartyTypeList.Value
EVNum = EvidenceID.Value
ActiveDocument.Variables("FormInfo") = EVParty & "|" & EVNum & "|" & "Other stuff"
Code:
Dim sArr() as String
sArr = Split(ActiveDocument.Variables("FormInfo"),"|")
If UBound(sArr) > 1 then
PartyTypeList.Value = sArr(0)
EvidenceID.Value = sArr(1)
MsgBox "Other stuff is: " & sArr(2)
End If
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#3
|
|||
|
|||
|
I need the name of the variable to be able to be different depending on what is put into a userform. So these are legal documents. The information is based off parties (Plaintifff, Defendant, etc) and their evidence numbers (1, 2,A, B, 2-D etc) but will not be the same on every single document. So on one document, you might have a document that is Plaintiff2 and DefendantA while on another you will have one that is Defendant2 and Plaintiff2. They change.
Later, I will have a function that will pull up every variable that starts with Plaintiff and every variable that starts with Plaintiff and list them. So the values of the varibles for DefendantA and Plaintifff2 will involve information such as their page numbers, which I will be using an array for. I have figured out most of everything except for naming the variables to pull the information from. I have an entirely different way to do the same thing, but it involves a different method of using comments in a document that I wasn't wanting to use and wanted to see if there was going to be a way to just name variables on teh document. |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Show userForm from variable | Cosmo | Word VBA | 5 | 01-31-2018 12:59 PM |
Assigning a string variable to a userform label caption
|
Larry_1 | Excel Programming | 3 | 12-18-2017 06:59 AM |
| Project - variable data fields | pmarc | Word | 7 | 04-04-2013 05:07 PM |
| 30+ days Variable Day Date Calculations via Fields | ztag | Word | 2 | 01-06-2012 11:12 AM |
| Variable fields? | Emalee77 | PowerPoint | 0 | 01-30-2011 05:58 PM |