Document Variable

L

Lilbit

When I try to type the document variable and value in the document, I get
the error message "No Document Variable Supplied." Help!! What I'm
typing in is: "Password", Value:=whatever. Of course, I don't have to
type in DOCVARIABLE because it is provided automatically. Thanks in
advance for your help.
 
J

Jonathan West

You need to create a document variable in the document for the field to pick
up.

With the document open, open the VBA editor, and type the following into the
immediate window

ActiveDocument.Variables("Password") = "Mypassword"

Than save the document


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
L

Lilbit

Ok, let me get this straight:

Step 1:
Open the document
Tools
Visual Basic Editor
Now, when I open it, it is blank
so, click on Insert Model
Choose class module
Insert: ActiveDocument.Variables("Password") = "whatever"
close the window
Then save the document

Step 2:
Insert
Field
Document Automation (on left hand side)
DocVariable (on right hand side)
Beside DocVariable, type: "Password", Value:="whatever"

Thanks in advance for your help!!
 
J

Jean-Guy Marcil

Lilbit was telling us:
Lilbit nous racontait que :
Ok, let me get this straight:

Not quite.

You do not need to add a module:
Step 1:
Open the document
Tools (or ALT-F11)
Visual Basic Editor

Here, do CTRL-G to open the immediate Window
Type
ActiveDocument.Variables("Password") = "whatever"
in that window
Then save the document
(Of course you will eventually save, but it is not necessary for the next
step.
Step 2 will work immediately, regardless of the Saved state of the document,
as long as the Doc Variable has been created)

Do not type the value:
Step 2:
Insert
Field
Document Automation (on left hand side)
DocVariable (on right hand side)
Here you do not need to type the value.
{DOCVARIABLE Password}
will automatically display the value.

May I ask why you want to display a password in a document?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
L

Lilbit

Hi Jean -- On July 15th, I was trying to find a way to hide my password in
the spell check macro (Macro Font was subject). I was going to try to
make it invisible, or possibly code it a way that the user couldn't
understand, but VBA would. You suggested I use document variables.
 
J

Jean-Guy Marcil

Lilbit was telling us:
Lilbit nous racontait que :
Hi Jean -- On July 15th, I was trying to find a way to hide my
password in the spell check macro (Macro Font was subject). I was
going to try to make it invisible, or possibly code it a way that the
user couldn't understand, but VBA would. You suggested I use
document variables.

Yes, I suggested document variables as a way to store the password in the
document, not on the page itself. The code I suggested was:

Dim GetPassword As String

ActiveDocument.Variables("myvar").Value = "MyPassword"

GetPassword = ActiveDocument.Variables("myvar").Value


Dim GetPassword As String
creates a variable.

ActiveDocument.Variables("myvar").Value = "MyPassword"
creates the document variable to store the password in the document
binary code

GetPassword = ActiveDocument.Variables("myvar").Value
retrieves the password into the variable created above.
Now you can use this variable.

What I do not understand is that if you control the password value you do
not need to store it anywhere, just use it in the code directly.

It is still not clear what you want to do with the password in your code. If
it is just a question of un protecting/reprotecting a form, then you do not
need document variables:

ActiveDocument.Unprotect "MyPassword"

'Do some stuff

ActiveDocument.Protect wdAllowOnlyFormFields, True, "MyPassword"

So why hide the password anywhere when all you need to do is use it directly
in the code?

The only time I have done something like hiding a password in a document
variable was when I had created my own system of setting a password,. that
meant that my code did not "know" the password that was created by the user,
instead, it called the document variable that the password setting routines
used.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
L

Lilbit

The form must under no circumstances be changed. Some individuals who use
the form, have an uncontrollable desire to change forms. Having a
password in a macro is only a temporary means of stopping them. Before I
was required to give them the ability to spell check the form, password
protecting the forms was pretty straightforward. Now, however, in order
for the spell check to work, the password to protect/unprotect the form is
in the macro. Some users will come to the conclusion that the password is
in the macro and try to find it.
 
J

Jonathan West

Lilbit said:
The form must under no circumstances be changed. Some individuals who use
the form, have an uncontrollable desire to change forms. Having a
password in a macro is only a temporary means of stopping them. Before I
was required to give them the ability to spell check the form, password
protecting the forms was pretty straightforward. Now, however, in order
for the spell check to work, the password to protect/unprotect the form is
in the macro. Some users will come to the conclusion that the password is
in the macro and try to find it.

You can protect the code in the macro.

How to prevent other users from seeing and changing your VBA code
http://www.word.mvps.org/FAQs/MacrosVBA/ProtectProject.htm

This isn't an absolute protection - there are password cracking tools out
there that will be able to get round this.

So ultimately, this problem does not have a perfect technical solution.

But it does sound like you are engaged in some kind of a game with these
employees. You try to secure the templates, and they try to find a way
round. If employees are making unauthorised changes to forms and the
organisation is suffering as a result, then management has to make it clear
that this is not acceptable, and if necessary apply sanctions to those who
won't mend their ways - up to and including firing repeat offenders.

If on the other hand these changes to the forms are not all that big a deal,
then you are wasting your time trying to secure the templates because
management won't back you when you complain about it.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top