PDA

View Full Version : Set the active Document



davidboutche
08-10-2009, 03:18 AM
I have a series of user forms that call different procedures using different aspects of office.

The very final thing I want to happen is for the word document that has been created from a template to be protected to stop changes to it.

I made this procedure that I placed in a module:

Sub formprotect()
'
Checkerdoc.Activate
activedocument.Protect Password:="qwerty", NoReset:=False, Type:= _
wdAllowOnlyFormFields
End Sub


I thought that I had set the variable when the first user form initialised and made it available to all procedure by calling using the sub:


Sub UserForm_Initialize()
Dim Checkerdoc As Document
Set Checkerdoc = ActiveDocument
'.....and so on...


When I run the complete program it returns the error 'object required'

I'm assuming it doesn't know what the activedocument is to protect?

Paul_Hossler
08-10-2009, 06:40 AM
My guess is that it's a variable scope problem.

Checkerdoc is is local to UserForm_Initialize and not visible to formprotect

Try putting


Dim Checkerdoc As Document


in your standard module OUTSIDE of any Sub()'s


Option Explicit
Public Checkerdoc As Document

Sub ........


Paul