Unprotecting Forms via VBA in Word 97

M

mr tom

I'm automating a pile of stuff in word 97 using VBA.
I have created a form which many staff complete and email back to me
(filename will of course vary).
I've protected it (inc password) to ensure it is correctly completed.
To ensure it travels safely through our corporate firewalls, no VB Code in
it (so can't standardise save name).

So - the problem:
I have a control file which operates on it and have VBA code which seems to
work (it will detect it as the only other active document, which will do for
now)
The control file does it's job fine once the form is unprotected, but
doesn't want to once the protection is in place.
I've tried various iterations of the unprotect command, as you'll see from
the sample code I've attached below.

I'd love to hear any suggestions you may have.

Many thanks in advance,

Tom.

Sub SaveReconForm()

' Switch to the recon form

' ActiveWindow.Next.Activate

' Unprotect the recon form

ActiveWindow.Next.Unprotect Password:="xyz"
ActiveWindow.Next.Activate

Documents (Next).Unprotect Password:="xyz"

' ActiveDocument.Unprotect Password:="xyz"

' Refer to scheme name and scheme number bookmarks and make them strings

Dim strSchemename As String
strSchemename = ActiveDocument.FormFields("SchemeName").Range.Text
Dim strSCN As String
strSCN = ActiveDocument.FormFields("SCN").Range.Text

' Save the recon form in j:\reconforms\RF - Schemename - SCN.doc
ActiveDocument.SaveAs FileName:="j:\reconstructions\Recon Forms\RF - " &
strSchemename & " - " & strSCN & ".doc"

End Sub
 
M

mr tom

Just to clarify this one - and make my question much simpler:

From one document, how would I go about unprotecting another (password
protected form) automatically?

I've tried code (the unprotect command), but as soon as the macro tries to
operate within the protected programme, it's like it hits a brick wall.

Anybody else tried this and got anywhere?

Many thanks,

Tom.
 
M

mr tom

Sorted it.

Works fine if you know the document name (so if it varies, then list box or
combo box to display all active docs, then user select form in question.

Code is therefore:

Documents("Doc1.doc").Activate
ActiveDocument.Unprotect Password:="tryme"
 

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