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 / February 2006

Tip: Looking for answers? Try searching our database.

Using VBA to remove worksheet protections

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian Beck - 27 Feb 2006 17:14 GMT
I have a form that end users have been using to submit reports.  There are
numerous form fields within the document and the data within those fields is
what I'm interested in.  It's relatively easy for me create a macro that
simply sets the document to save form data only and then save the data.  I
figure I can just load each form up, run the macro, close the form...and
repeat.  Except for one little problem.  When I created these forms
originally, I had password protected them so that the user could only enter
information into the form fields.  I'd like to also automate the process of
un-protecting the document, but I can't seem to figure out how to do that.

I know that I can put some code in an AutoOpen macro that I can use just for
the purpose of messing with these forms, but in using the syntax below, I
keep getting an error  [Runtime error "13"  Type mismatch]:

Sub AutoOpen()
With Options
   .LocalNetworkFile = False
   .AllowFastSave = False
   .BackgroundSave = True
   .CreateBackup = False
   .SavePropertiesPrompt = False
   .SaveInterval = 10
   .SaveNormalPrompt = False
   .DisableFeaturesbyDefault = False
End With
With ActiveDocument
   .ReadOnlyRecommended = False
   .EmbedTrueTypeFonts = False
   .SaveFormsData = True
   .SaveSubsetFonts = False
   .DoNotEmbedSystemFonts = True
   .Password = ""
   .WritePassword = ""
   .DisableFeatures = False
   .EmbedSmartTags = True
   .SmartTagsAsXMLProps = False
   .EmbedLinguisticData = True
   .Protect "wdNoProtection,,PASSWORD,,"
End With
End Sub

Obviously, PASSWORD would be replaced with the actual text of the password
for the form.

Any ideas are greatly appreciated.

-Brian
Tony Jollans - 27 Feb 2006 23:47 GMT
The reason for the type mismatch is that you have passed a string as the
first parameter when the Protect method expects a number.

However, if you correct that you will get a different error telling you that
you can't protect an already protected document.

To unprotect a document, use ActiveDocument.Unprotect.

--
Enjoy,
Tony

> I have a form that end users have been using to submit reports.  There are
> numerous form fields within the document and the data within those fields is
[quoted text clipped - 43 lines]
>
> -Brian
 
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.