Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-15-2013, 08:52 AM
Cosmo Cosmo is offline Macrobutton shifts view when document is protected for forms Windows Vista Macrobutton shifts view when document is protected for forms Office 2007
Competent Performer
Macrobutton shifts view when document is protected for forms
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default Macrobutton shifts view when document is protected for forms

I have a Word form which has several tables containing text entry and checkbox fields. I have a macrobutton on one of the pages to run a macro, but once the form is protected for forms, clicking on the Macrobutton shifts focus to the next page where the first checkboxes are. This prevents users from being able to double click on the macrobutton to run the macro since the macrobutton is no longer in the same position for the second click. It doesn't seem to do this if the document is protected for comments or any other setting, just form fields.



Is this a known issue with macrobuttons and protected forms? Is there any other way to run a macro from a click in the document?
Reply With Quote
  #2  
Old 10-15-2013, 09:34 AM
Charles Kenyon Charles Kenyon is offline Macrobutton shifts view when document is protected for forms Windows Vista Macrobutton shifts view when document is protected for forms Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

When a user clicks anywhere in a document protected for forms (other than in an active formfield) the focus moves to a page with formfields that are active.

Assuming you are using legacy form fields, you can designate a macro to run on exit from a formfield.

You can put the following in an AutoOpen and AutoNew macro in your form template:

Code:
Sub AutoOpen()
' Set macro button response to one click rather than double-click
' Macro written by Charles Kenyon based on help from Bill Coan on newsgroup
'
   Options.ButtonFieldClicks = 1
'
End Sub
This makes a single click activate the macrobutton.

Making Forms with Microsoft Word
Reply With Quote
  #3  
Old 10-15-2013, 10:17 AM
Cosmo Cosmo is offline Macrobutton shifts view when document is protected for forms Windows Vista Macrobutton shifts view when document is protected for forms Office 2007
Competent Performer
Macrobutton shifts view when document is protected for forms
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
When a user clicks anywhere in a document protected for forms (other than in an active formfield) the focus moves to a page with formfields that are active.

Assuming you are using legacy form fields, you can designate a macro to run on exit from a formfield.

You can put the following in an AutoOpen and AutoNew macro in your form template:

Code:
Sub AutoOpen()
' Set macro button response to one click rather than double-click
' Macro written by Charles Kenyon based on help from Bill Coan on newsgroup
'
   Options.ButtonFieldClicks = 1
'
End Sub
This makes a single click activate the macrobutton.

Making Forms with Microsoft Word
Thanks, I'll look into that.

According to the help files for the 'Options' object:
Quote:
Represents application and document options in Word. Many of the properties for the Options object correspond to items in the Options dialog box.
Is the ButtonFieldClicks an application-level setting? Do I need to reset it after my form is completed? Is this an option available in the UI?

I'm assuming there's no way to set this for the document so that it travels with the document without scripting.
Reply With Quote
  #4  
Old 10-15-2013, 11:06 AM
Charles Kenyon Charles Kenyon is offline Macrobutton shifts view when document is protected for forms Windows Vista Macrobutton shifts view when document is protected for forms Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

I believe it to be an application-level setting that applies to that Word session.
Haven't tested it.

I know of no way to set the document for this setting without a macro. Once the document is on a different machine, it will have no effect until the setting is run on that machine.

If the macro is in the template and a document based on the template is opened or created, it will be run so long as the document remains attached to the template.

It should be possible to first capture that option state in a document variable when the macro is run and return to that state in a macro that responds to the Document_Close event. I have not attempted this because, frankly, I want the option set this way on all of the machines in my office. I have a number of macrobutton field using checkbox autotext in my non-protected legacy forms.

Single-Click Checkboxes in non-protected forms
Reply With Quote
  #5  
Old 10-15-2013, 01:28 PM
Cosmo Cosmo is offline Macrobutton shifts view when document is protected for forms Windows Vista Macrobutton shifts view when document is protected for forms Office 2007
Competent Performer
Macrobutton shifts view when document is protected for forms
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
I believe it to be an application-level setting that applies to that Word session.
Haven't tested it.

I know of no way to set the document for this setting without a macro. Once the document is on a different machine, it will have no effect until the setting is run on that machine.

If the macro is in the template and a document based on the template is opened or created, it will be run so long as the document remains attached to the template.

It should be possible to first capture that option state in a document variable when the macro is run and return to that state in a macro that responds to the Document_Close event. I have not attempted this because, frankly, I want the option set this way on all of the machines in my office. I have a number of macrobutton field using checkbox autotext in my non-protected legacy forms.

Single-Click Checkboxes in non-protected forms
Thanks again. It does appear to be a document level setting, creating a new document retains the currently set value.

I believe I should be able to get away with using the 'WindowActivate' and 'WindowDeactivate' events to change and reset this value so that it won't affect any other documents the user has open at the time (just in case). I did a quick test, and that seems to be working.
Reply With Quote
  #6  
Old 10-15-2013, 01:57 PM
Charles Kenyon Charles Kenyon is offline Macrobutton shifts view when document is protected for forms Windows Vista Macrobutton shifts view when document is protected for forms Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by Cosmo View Post
Thanks again. It does appear to be a document level setting, creating a new document retains the currently set value.

I believe I should be able to get away with using the 'WindowActivate' and 'WindowDeactivate' events to change and reset this value so that it won't affect any other documents the user has open at the time (just in case). I did a quick test, and that seems to be working.
Thank you for the update. Again, I learn something new!
Reply With Quote
  #7  
Old 10-15-2013, 02:16 PM
Cosmo Cosmo is offline Macrobutton shifts view when document is protected for forms Windows Vista Macrobutton shifts view when document is protected for forms Office 2007
Competent Performer
Macrobutton shifts view when document is protected for forms
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
Thank you for the update. Again, I learn something new!
This is the code I ended up using in a MacroButton Controller class:

Code:
Option Explicit
Private WithEvents wordApp As Word.Application
Private currentButtonClick As Integer
Private TemplateDoc As Document
'*************************************************************************
' Initialize class - Create objects and set values to defaults.
'*************************************************************************
Private Sub Class_Initialize()
    currentButtonClick = Options.ButtonFieldClicks
    Set wordApp = Application
    Set TemplateDoc = ActiveDocument
    Call setButtonClick
End Sub
'*************************************************************************
' Terminate class - Cleanup code.
'*************************************************************************
Private Sub Class_Terminate()
    Call restoreButtonClick
    Set wordApp = Nothing
    Set TemplateDoc = Nothing
End Sub
'*************************************************************************
' Application EVENT HANDLERS
'*************************************************************************
Private Sub wordApp_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
    If CheckDoc(Doc) Then
        Call restoreButtonClick
    End If
End Sub
Private Sub wordApp_WindowActivate(ByVal Doc As Document, ByVal Wn As Window)
    If CheckDoc(Doc) Then
        Call setButtonClick
    End If
End Sub
Private Sub wordApp_WindowDeactivate(ByVal Doc As Document, ByVal Wn As Window)
    If CheckDoc(Doc) Then
        Call restoreButtonClick
    End If
End Sub
''*************************************************************************
'' UTILITY functions
''*************************************************************************
Private Function CheckDoc(Doc As Document) As Boolean
    If Not (TemplateDoc Is Nothing) Then
        If Not (Doc Is Nothing) Then
            CheckDoc = (Doc = TemplateDoc)
        End If
    End If
End Function
Private Function setButtonClick()
    Options.ButtonFieldClicks = 1
End Function
Private Function restoreButtonClick()
    Options.ButtonFieldClicks = currentButtonClick
End Function
I appreciate the help, I wouldn't have known that there was a setting for this without your responses. Thanks again
Reply With Quote
  #8  
Old 10-15-2013, 03:28 PM
Charles Kenyon Charles Kenyon is offline Macrobutton shifts view when document is protected for forms Windows Vista Macrobutton shifts view when document is protected for forms Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Very nice. Beyond my pay grade!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macrobutton shifts view when document is protected for forms Disable Protected View in Microsoft Excel kwon34 Excel 2 09-27-2013 08:38 PM
Macrobutton shifts view when document is protected for forms Cannot open emailed documents in Word 2010 - Protected View Andrewjmarino Word 8 09-05-2013 03:58 PM
Macrobutton shifts view when document is protected for forms Spell checker in Word protected forms Frankwlc Word 3 08-02-2013 12:15 PM
Using bookmarks in a protected document Bill Stemp Word 0 10-16-2010 06:47 AM
MacroButton MednataMiza Word 0 06-29-2010 01:59 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:44 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft