VBA for opening a dialog box without losing focus on toolbar

J

Jack_Feeman

I have successfully written a macro to open Document Properties dialog box so
users can enter repetitive data to populate fields throughout the body and
header/footer.

Sub ShowProperties()
'
'Shows the Properties Dialog Box
On Error Resume Next
WordBasic.FileProperties
On Error GoTo 0
' Macro recorded 10/4/2006 by Jack Feeman
'
End Sub

However, after entering in the (meta)data and clicking the OK button, the
dialog box closes and so does the custom toolbar that contains the button
that opened it. Even though clicking anywhere in the background brings it
back, we want a positive user experience and someone will always forget to
click to bring it back. If I manually open/close the dialog box, the custom
toolbar stays put. If I do the same thing via a custom button the toolbar and
if another window is open in the background it will become the focus when I
close the dialog box.

Anything I could add to the macro that will bring it back automatically upon
closing the dialog box?

The "Record new Macro" toolbar always disables itself if I try to change
tabs on the Document Properties dialog box or in any other way try to do
anything else in the dialog box except for opening it. If I click OK during
the recording of the macro, the "Record New Macro" toolbar will become
enabled again, but I do not want to close it since the user will not get a
chance to enter any data.

What I am trying to do in addition to opening the Document Properties dialog
for data entry; I wanted to select the Custom tab of the dialog box where all
the information to be entered is consolidated. If I click on the tab, it does
not select it and the "record New Macro" toolbar disables itself.

Thanks
Jack
 
J

Jack_Feeman

Thanks Jonathan for the quick response.
Goal was to create a foolproof way of entering a lot of repetitive data into
the document properties of a new document based on a template we created.

Using the 'Record New Macro" function, I:
• Clicked File>Document Properties
Then ended the recording. (This is because if I clicked the Customs tab as I
wanted to direct the focus to that tab for the user would cause the "Record
New Macro" tool bar to become unenabled and I was not able to enable it
again. So I had to settle for just opening the Properties dialog box.)

Using the "Customize" function, I:
• created a custom toolbar
• created a custom button from the macro
• both were created in a custom template

Problems:
• The user click the custom button and the Properties Dialog box displays
• After the user enters the data into the properties dialog box and clicks
OK; the custom tool bar disappears and takes a click of the mouse anywhere on
the screen to bring it back (however, this has "freaked out some of our
users", since it is unexpected). If there is another window open in the
background it will also bring that window to the front putting the focus on
that window.

Any help in adding code to the macro that would keep the custom toolbar
visible after closing the properties dailog box and the current window active
would be greatly appreciated. Also some code to set the focus to the Custom
tab of the document properties dialog box after it opens would be great also.
Thanks again
 
J

Jonathan West

Ah, I wasn't reading sufficiently carefully the first time. I understand
now. It is one of the oddities of Word - no obvious reason for it. If the
toolbar is docked rather than floating it doesn't disappear. But you can get
it not to disappear anyway if you change your macro to this.

Sub ShowProperties()
'
'Shows the Properties Dialog Box
CommandBars.FindControl(id:=750, Visible:=False).Execute

End Sub


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
 
J

Jack_Feeman

Thanks Johnathan that will help immensely with user experience.

Any luck in getting the Customs tab of the Document Properties dailog box to
default?

Thanks again
Jack
 
J

Jonathan West

Jack_Feeman said:
Thanks Johnathan that will help immensely with user experience.

Any luck in getting the Customs tab of the Document Properties dailog box
to
default?

You can experiment with using Sendkeys, but I would recommend against it.
Sendkeys is flaky at the best of time. Clicking the custom tab when the
dialog appears will have to be a user education issue.

If you want to get away from this altogether, and want to make only the
specific properties available on the form that you want the user to enter,
then you can create your own UserForm for the purpose. Have a textbox on the
form for each property, and then read/write the properties using the
CustomDocumentProperties collection.

if you are not familiar with UserForms, this article will help you

How to create a Userform
http://www.word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

The code example inserts text a bookmarks rather than setting custom
document properties, but it should be fairly easy to adapt.
 

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