Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2005

Tip: Looking for answers? Try searching our database.

Document Variable

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lilbit - 21 Jul 2005 16:42 GMT
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.
Jonathan West - 21 Jul 2005 17:22 GMT
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

Signature

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

> 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.
Lilbit - 21 Jul 2005 20:38 GMT
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!!
Jean-Guy Marcil - 21 Jul 2005 21:10 GMT
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?

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Lilbit - 21 Jul 2005 21:38 GMT
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.
Jean-Guy Marcil - 22 Jul 2005 15:17 GMT
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.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Lilbit - 22 Jul 2005 15:39 GMT
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.
Jonathan West - 22 Jul 2005 16:32 GMT
> The form must under no circumstances be changed.  Some individuals who use
> the form, have an uncontrollable desire to change forms.  Having a
[quoted text clipped - 4 lines]
> 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.

Signature

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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.