Prompting for Document Properties loses Document Focus

J

Jeremy W

Does anyone have any suggestions why my template loses focus from the
document when a macros I've written opens the File Properties dialog
box. T

The macro is:

Sub Document_New()
On Error Resume Next
Application.Run "FileProperties"
End Sub

Basically, when you create a new document from the template, the file
properties dialog box opens. If you then close it, then focus goes to
any other program except the new document (or so it seems). It doesn't
seem very impressive, especially as I want all work group templates to
auto prompt for properties in this way.

Many thanks for your interest and help.

Jeremy
 
H

Helmut Weber

Hi Jeremy,
Application.Run "FileProperties"
takes you to quite another application. It is like starting Photoshop
and remaining there. This application is then closed, and the next
application, whatsoever, gets the focus.
What you got to do is, replace
Application.Run "FileProperties"
by
Dialogs(wdDialogFileSummaryInfo).Show

Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word XP, Win 98
 
J

Jeremy W

Hi Helmut,

Thank you for your quick response.

I had already tried the wdDialogSummaryInfo route, but unfortunately
the summary does not include all the fields that we need to review
when creating a new document from the template. The main missing field
is the Company - as this can vary depending on the project.

Any other suggestions?

Jeremy
 
H

Helmut Weber

Hi Jeremy,
Any other suggestions?
not really. It's either you create your own userform,
to retrieve and write all the file properties,
that you are interested in, or you use an extra
simple inputbox, to ask for the company's name,
or you may have a close look at:
http://word.mvps.org/FAQs/MacrosVBA/DSOFile.htm
and adapt it to your needs.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word XP, NT 4.0
 
A

Alex

Hi Jeremy

Those nice people at MVP helped me with a similar problem
last year, here's the final solution.

Create you template with a userform and an AutoNew macro
that calls up the user form when the document is first
created.

Attached the following code as the userform code

Private Sub OK_Click()
Dim oDoc As Document
Dim oControl As Control
Dim strControl As String


Set oDoc = ActiveDocument

For Each oControl In Me.Controls

If LCase(TypeName(oControl)) = "textbox" Then
strControl = oControl.Name

If strControl = "Title" Or strControl = "Subject"
Then
If Not oControl.Value = "" Then
oDoc.BuiltInDocumentProperties
(strControl).Value = oControl.Value
End If
Else
If DoesDocPropExist(strControl) = False Then
oDoc.CustomDocumentProperties.Add _
Name:=strControl, _
LinkToContent:=False, _
Value:="<empty>", _
Type:=msoPropertyTypeString
End If
If Not oControl.Value = "" Then
oDoc.CustomDocumentProperties
(strControl).Value = oControl.Value
End If
End If
End If
Next
Unload Me
End Sub

Private Function DoesDocPropExist(DocPropName As String)
As Boolean
On Error GoTo DoesNotExist
DoesDocPropExist = _
(DocPropName =
ActiveDocument.CustomDocumentProperties(DocPropName).Name)
Exit Function
DoesNotExist:
Err.Clear
End Function


This code is great, what it does is, it looks at the name
of the userform textboxes, and checks the name against the
doc property names. In this case title & Subject,

If you've named the textboxes title or subject it takes
the info entered into these boxes and populates the
corresponding property fields with that information.

Here's the good bit, if you add a third, fourth, fifth etc
textbox and give them unique names then the code will
create custom properties based on the textbox names.

Hence once you have the code all you have to do to create
templates that gather different information is simply
change the names of the textboxes. The code never needs
to be changed.

I currently use this code in over 40 different templates
ranging from letters to technical documents and each
template gathers different infromation that is stored in
the Built in properties and the custom properties.

Hope this helps

Alex
 

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