PDA

View Full Version : Enable Drawing and Picture Toolbar Items in Protected Form



abvnewbie
07-17-2008, 11:36 AM
In Word 2003, a number of useful standard toolbar buttons are disabled when a form is protected. These buttons remain disabled even when the user is working in an unprotected section of the Word form. Is there a simple way to enable these buttons? If not, is there a simple way to emulate the function of these buttons (for instance, the crop button) with a VBA macro?

OTWarrior
07-21-2008, 03:49 AM
If I remember rightly, if protection is on then the design option is disabled, even if only a section of the document is protected. The only way I can think of off the top of my head would be to unprotect the document in order for the user to enter design mode, but that kind of removes the whoel point of having it protected. Why do you want to give the user so much control?

You can have macros for each function (like you said the crop button) that performs a certain function, that unprotects the document and enters design mode to do so, then reverses those option when it is done.

ActiveDocument.Unprotect Password:=""
ActiveDocument.ToggleFormsDesign

'do your code here, example:
Selection.InlineShapes.AddOLEControl ClassType:="Forms.CheckBox.1"

ActiveDocument.ToggleFormsDesign
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""

abvnewbie
07-21-2008, 10:14 AM
Why do you want to give the user so much control?


There's a free form section of the document where the user needs to have access to picture cropping and autoshape features. Unfortunately, these features are locked even in an unprotected part of the document. My problem is that I don't know nearly enough to emulate these features in a macro (and I'm not even certain that it can be done in a free form fashion). The Activedocument.Inlineshapes commands seem limited to fixed geometry parameters (fixed height and width) which must be embedded within the code which is too restrictive and hardly worth the trouble. The only code I've managed to find is a lengthy piece which emulates the spell check function. If anyone has any ideas where I can find code that emulates the picture cropping and autoshapes functions (in a dynamic manner) please let me know.

macropod
07-21-2008, 04:09 PM
Hi abvnewbie,

The simplest solution might be to link your form to a unprotected document (via an INCLUDETEXT field) in which the user has access to the full menus.

OTWarrior
07-22-2008, 12:07 AM
How about this?

ActiveDocument.Unprotect Password:=""
ActiveDocument.ToggleFormsDesign

'crops by a certain ammount
Selection.InlineShapes(1).PictureFormat.CropRight = 42#

ActiveDocument.ToggleFormsDesign
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""

you would be best off creating your own toolbar for the document, but this way you can make sure the features get turned on as and when they are needed. You'd be best off making the protect and unprotect code as functions to call each time than replicating the code for each drawing button.

Use the record macros button to find out the code for each command you wish to give the user.

Notes the number 42 can be changed for something more flexible, but I will leave that for you to have a play with.

PS: MacroPod are you following me around :rotlaugh:

abvnewbie
07-22-2008, 12:04 PM
'crops by a certain ammount
Selection.InlineShapes(1).PictureFormat.CropRight = 42#


yeah, tried that but it's not nearly as dynamic as the actual crop function (crop increment or height/width is hard coded and not user selectable). i suppose i could come up with a crop increment dial within a userform to make the crop increment a more dynamic value. was really hoping that there was a way to enable the actual crop function and autoshape functions (wishful thinking i suppose).

OTWarrior
07-23-2008, 01:12 AM
I know it's not ideal, but see what you think of this...

Public Sub UserCrop() 'crops by a user inputted amount
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=""
End If

ActiveDocument.InlineShapes(1).Select
Selection.InlineShapes(1).PictureFormat.CropRight = Int(InputBox("Please enter a value to crop to the RIGHT by"))
Selection.InlineShapes(1).PictureFormat.CropLeft = Int(InputBox("Please enter a value to crop to the LEFT by"))
Selection.InlineShapes(1).PictureFormat.CropBottom = Int(InputBox("Please enter a value to crop to the BOTTOM by"))
Selection.InlineShapes(1).PictureFormat.CropTop = Int(InputBox("Please enter a value to crop to the UP by"))

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End Sub

macropod
07-23-2008, 03:54 AM
Hi folks,

I'd like to suggest a different approach:
Add a menu item to the Form that, when clicked, temporarily creates a new Word Document, copies the image to that for editing and then, when that document is closed or the user attempts to save it, the image in the Form is replaced with the image from the temporary document, which is then closed without saving.

Naturally, you'd need some code the check that the image hadn't been deleted or modified in an unacceptable way, but that shouldn't be too hard to manage. And, properly coded, it doesn't matter what else the user does in the temporary document.

abvnewbie
07-24-2008, 09:06 AM
Hi All :hi:



Add a menu item to the Form that, when clicked, temporarily creates a new Word Document...

Yeah, that's essentially the same as what I've got now. At present I've got a separate form toolbar and one of the buttons does this:

Selection.InlineShapes.AddOLEObject ClassType:="Word.Document.8", FileName _
:="", LinkToFile:=False, DisplayAsIcon:=False


The embedded MSWord object then opens for editing in a completely unprotected document and when closed it is pulled into the form. It's a work around but I'm exploring another option. I'd prefer (for the crop function) to create a userform that will allow the user to dynamically crop the image.

:think: Does anyone know the command for returning the current height and width values of a Selection.InlineShape (picture)?

OTWarrior
07-24-2008, 09:22 AM
Selection.InlineShapes(1).Height

&

Selection.InlineShapes(1).Width
?

abvnewbie
07-24-2008, 03:53 PM
Here's a first cut at a tool (userform) for emulating the crop. Thus far it's the most dynamic way I can think of to do this.


In the attachment, you'll need to turn on the "Crop" Toolbar (View - Toolbars - "Crop").


The crop increment is set to 10% for single click and 30% for a double click. This is necessary to make it flexible in working with multiple pictures where the aspect ratios either vary a great deal or the overall size of the picture is relatively small (i.e. a fixed hard-coded increment could crop the entire picture if the picture is small enough or the increment in the code is relatively large).