Jean-Guy
Wed Aug 03 13:58:11 CDT 2005
Gaz uk was telling us:
Gaz uk nous racontait que :
> This isn't the exact code, but you get the idea......
>
> Public vName
>
> Private Sub CommandButton1_Click()
> x = MsgBox(vName)
> End Sub
>
> Private Sub Document_Open()
> vName = InputBox("Input Name")
>
> Set vCmdSubmit =
> Selection.InlineShapes.AddOLEControl(ClassType:="Forms.CommandButton.1")
> With vCmdSubmit.OLEFormat.Object
> .Name = "CommandButton1"
> .Caption = "Submit"
> .AutoSize = True
>
> End With
> End Sub
>
Where is Public vName declared (In which module)?
From your "inexact" code, it looks like it is declared in the userform code
module. It helps those who are trying to help (on their own time) to provide
as much information as possible.
This is fine as long as the variable is not needed by other modules.
In your case, you should declare your public variable in a regular module
(Not in ThisDocument module, which, like the userform module, is a class
module). Class modules do not share public variables with other modules.
So, create a regular module and declare your public variables there.
I know some people frown on public variables... For example, in your case,
there would be a way to pass the variable as a parameter when calling the
userform and avoid the need for a public variable...
But, for simple stuff like this, I do not think that a public variable can
be a problem.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site:
http://www.word.mvps.org