Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-21-2011, 11:39 AM
KJJ KJJ is offline Help with Document Properties Prompt Macro Windows Vista Help with Document Properties Prompt Macro Office 2007
Novice
Help with Document Properties Prompt Macro
 
Join Date: Apr 2011
Posts: 6
KJJ is on a distinguished road
Default Help with Document Properties Prompt Macro

I have butchered an existing macro (as I don't have the knowledge to write one from scratch) to attempt to prompt Word (2007/2010) users in my workplace to add document properties at the point of closing their document (I have included the macro below). It works fine other than I don't know how to achieve two other specific aims:

1. How can I prompt for the property called 'Status'? I want users to be prompted so that it will save the document with Draft/Final status etc.

2. The macro at the moment has specific text pre-included in the form (e.g. add author name here), but how do i set the default text to be that already existing for that property, so the users don't have to start from scratch when adding this information each time they close the document?

Any help much apprecaited.

Macro:

Sub AutoClose()

Dim Title As String
Dim Author As String
Dim Subject As String
Dim oStory As Range
Dim oShp As Shape

Title = InputBox("Enter the Document Title:", "Title", "Title Here")
Author = InputBox("Enter the Document Author:", "Author", "Author Here")
Subject = InputBox("Enter the Client and Site Name:", "Subject", "Client - Site Name Here")
ActiveDocument.BuiltInDocumentProperties("Title"). Value = Title


ActiveDocument.BuiltInDocumentProperties("Subject" ).Value = Subject
ActiveDocument.BuiltInDocumentProperties("Author") .Value = Author
For Each oStory In ActiveDocument.StoryRanges
Do
On Error Resume Next
oStory.Fields.Update
Select Case oStory.StoryType
Case 6, 7, 8, 9, 10, 11
If oStory.ShapeRange.Count > 0 Then
For Each oShp In oStory.ShapeRange
If oShp.TextFrame.HasText Then
oShp.TextFrame.TextRange.Fields.Update
End If
Next oShp
Set oShp = Nothing
End If
Case Else
'Do Nothing
End Select
On Error GoTo 0
'Get next linked story (if any)
Set oStory = oStory.NextStoryRange
Loop Until oStory Is Nothing
Next oStory
Set oStory = Nothing
End Sub
Reply With Quote
  #2  
Old 04-21-2011, 10:22 PM
macropod's Avatar
macropod macropod is online now Help with Document Properties Prompt Macro Windows 7 32bit Help with Document Properties Prompt Macro Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi KJJ,

Much of your code isn't related to the task you've described, so I've omitted it from the code below. Also, instead of using an 'Document_Close' macro, I've used a 'AutoClose' macro, which you place in the template's 'ThisDocument' module. The code below provides the prompts you're after, and only updates the properties if anything's changed. That way, the document doesn't give unnecessary 'save' prompts (though if you do include your other code for updating fields, you're going to get 'save' prompts anyway).
Code:
Private Sub Document_Close()
Dim StrOldTitle As String, StrNewTitle As String
Dim StrOldAuthor As String, StrNewAuthor As String
Dim StrOldSubject As String, StrNewSubject As String
Dim bSaved As Boolean
With ActiveDocument
  bSaved = .Saved
  StrOldTitle = .BuiltInDocumentProperties("Title").Value
  StrOldAuthor = .BuiltInDocumentProperties("Author").Value
  StrOldSubject = .BuiltInDocumentProperties("Subject").Value
  StrNewTitle = InputBox("Enter the Document Title:", "Title", StrOldTitle)
  StrNewAuthor = InputBox("Enter the Document Author:", "Author", StrOldAuthor)
  StrNewSubject = InputBox("Enter the Client and Site Name:", "Subject", StrOldSubject)
  If StrOldTitle <> StrNewTitle Then _
    .BuiltInDocumentProperties("Title").Value = StrNewTitle
  If StrOldAuthor <> StrOldAuthor Then _
    .BuiltInDocumentProperties("Author").Value = StrNewAuthor
  If StrOldSubject <> StrOldSubject Then _
    .BuiltInDocumentProperties("Subject").Value = StrNewSubject
  If bSaved = True And .Saved = True Then Exit Sub
End With
End Sub
PS: When posting code, please format it and use Code tags.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-26-2011, 01:27 AM
KJJ KJJ is offline Help with Document Properties Prompt Macro Windows Vista Help with Document Properties Prompt Macro Office 2007
Novice
Help with Document Properties Prompt Macro
 
Join Date: Apr 2011
Posts: 6
KJJ is on a distinguished road
Default

That is extremely helpful. Many thanks for that. Much appreciated.

Do you know the answer to my first query: How can I prompt for the property called 'Status'?

Thanks again.

Karl
Reply With Quote
  #4  
Old 04-26-2011, 01:45 AM
macropod's Avatar
macropod macropod is online now Help with Document Properties Prompt Macro Windows 7 32bit Help with Document Properties Prompt Macro Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Karl,

For 'Status', you'd simply add another set of variables and the corresponding code to get/set its values. For example:
Code:
Dim StrOldStatus As String, StrNewStatus As String
...
StrOldStatus = .BuiltInDocumentProperties("Status").Value
...
StrNewStatus = InputBox("Enter the Document Status:", "Status", StrOldStatus)
...
If StrOldStatus<> StrNewStatus Then _
  .BuiltInDocumentProperties("Status").Value = StrNewStatus
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 04-26-2011, 01:51 AM
KJJ KJJ is offline Help with Document Properties Prompt Macro Windows Vista Help with Document Properties Prompt Macro Office 2007
Novice
Help with Document Properties Prompt Macro
 
Join Date: Apr 2011
Posts: 6
KJJ is on a distinguished road
Default

Thanks for the quick reply. I tried that and unfortunately it doesn't seem to work. I get an error on this line:

StrOldStatus = .BuiltInDocumentProperties("Status").Value

It maybe suggests that 'status' is not a 'Built In Document Property' or that 'status' is not the correct description?

Thnaks

Karl
Reply With Quote
  #6  
Old 04-26-2011, 02:00 AM
macropod's Avatar
macropod macropod is online now Help with Document Properties Prompt Macro Windows 7 32bit Help with Document Properties Prompt Macro Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Karl,

OK, on-screen it's called 'Status', but in code it's called 'Content Status'. So you'll need to change the two references from:
.BuiltInDocumentProperties("Status").Value
to:
.BuiltInDocumentProperties("Content Status").Value
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 04-26-2011, 02:34 AM
KJJ KJJ is offline Help with Document Properties Prompt Macro Windows Vista Help with Document Properties Prompt Macro Office 2007
Novice
Help with Document Properties Prompt Macro
 
Join Date: Apr 2011
Posts: 6
KJJ is on a distinguished road
Default

Thanks Paul,

That sorted out the status issue nicely. I think there were a couple of issues with the last few lines of your code, so i have amended this as below. Does this look right to you? Seems to work ok.

Many thanks again.

Karl


Code:
Private Sub Document_Close()
  Dim StrOldTitle As String, StrNewTitle As String
  Dim StrOldAuthor As String, StrNewAuthor As String
  Dim StrOldSubject As String, StrNewSubject As String
  Dim StrOldStatus As String, StrNewStatus As String
  Dim bSaved As Boolean
  With ActiveDocument
    bSaved = .Saved
    StrOldTitle = .BuiltInDocumentProperties("Title").Value
    StrOldAuthor = .BuiltInDocumentProperties("Author").Value
    StrOldSubject = .BuiltInDocumentProperties("Subject").Value
    StrOldStatus = .BuiltInDocumentProperties("Content Status").Value
    StrNewTitle = InputBox("Enter the Document Title:", "Title", StrOldTitle)
    StrNewAuthor = InputBox("Enter the Document Author:", "Author", StrOldAuthor)
    StrNewSubject = InputBox("Enter the Client and Site Name:", "Subject", StrOldSubject)
    If StrOldTitle <> StrNewTitle Then _
      .BuiltInDocumentProperties("Title").Value = StrNewTitle
    If StrOldAuthor <> StrNewAuthor Then _
      .BuiltInDocumentProperties("Author").Value = StrNewAuthor
    If StrOldStatus <> StrNewStatus Then _
      .BuiltInDocumentProperties("Content Status").Value = StrNewStatus
    If StrOldSubject <> StrNewSubject Then _
      .BuiltInDocumentProperties("Subject").Value = StrNewSubject
    If bSaved = True And .Saved = True Then Exit Sub
  End With
  End Sub
Reply With Quote
  #8  
Old 04-26-2011, 02:52 AM
macropod's Avatar
macropod macropod is online now Help with Document Properties Prompt Macro Windows 7 32bit Help with Document Properties Prompt Macro Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Karl,

Oops! Here's the corrected (and complete) code:
Code:
Private Sub Document_Close()
Dim StrOldTitle As String, StrNewTitle As String
Dim StrOldAuthor As String, StrNewAuthor As String
Dim StrOldSubject As String, StrNewSubject As String
Dim StrOldStatus As String, StrNewStatus As String
Dim bSaved As Boolean
With ActiveDocument
  bSaved = .Saved
  StrOldTitle = .BuiltInDocumentProperties("Title").Value
  StrOldAuthor = .BuiltInDocumentProperties("Author").Value
  StrOldSubject = .BuiltInDocumentProperties("Subject").Value
  StrOldStatus = .BuiltInDocumentProperties("Content Status").Value
  StrNewTitle = InputBox("Enter the Document Title:", "Title", StrOldTitle)
  StrNewAuthor = InputBox("Enter the Document Author:", "Author", StrOldAuthor)
  StrNewSubject = InputBox("Enter the Client and Site Name:", "Subject", StrOldSubject)
  StrNewStatus = InputBox("Enter the Document Status:", "Status", StrOldStatus)
  If StrOldTitle <> StrNewTitle Then _
    .BuiltInDocumentProperties("Title").Value = StrNewTitle
  If StrOldAuthor <> StrNewAuthor Then _
    .BuiltInDocumentProperties("Author").Value = StrNewAuthor
  If StrOldSubject <> StrNewSubject Then _
    .BuiltInDocumentProperties("Subject").Value = StrNewSubject
  If StrOldStatus <> StrNewStatus Then _
    .BuiltInDocumentProperties("Content Status").Value = StrNewStatus
  If bSaved = True And .Saved = True Then Exit Sub
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 04-26-2011, 02:57 AM
KJJ KJJ is offline Help with Document Properties Prompt Macro Windows Vista Help with Document Properties Prompt Macro Office 2007
Novice
Help with Document Properties Prompt Macro
 
Join Date: Apr 2011
Posts: 6
KJJ is on a distinguished road
Default

Almost there! ...

Quote:
Originally Posted by macropod View Post
StrNewStatus = InputBox("Enter the Document Status:", "Status", StrOldStatus)
Should be:
StrNewStatus = InputBox("Enter the Document Status:", "Content Status", StrOldStatus)

Many thanks

Karl
Reply With Quote
  #10  
Old 04-26-2011, 04:39 AM
macropod's Avatar
macropod macropod is online now Help with Document Properties Prompt Macro Windows 7 32bit Help with Document Properties Prompt Macro Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Karl,

That change is inconsequential so far as the macro's correct execution is concerned. What gets displayed in the InputBox is independent of the doc property's name.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 04-26-2011, 05:45 AM
KJJ KJJ is offline Help with Document Properties Prompt Macro Windows Vista Help with Document Properties Prompt Macro Office 2007
Novice
Help with Document Properties Prompt Macro
 
Join Date: Apr 2011
Posts: 6
KJJ is on a distinguished road
Default

Ok, thanks.

Karl
Reply With Quote
  #12  
Old 11-10-2016, 07:07 PM
Vaha Vaha is offline Help with Document Properties Prompt Macro Windows 7 64bit Help with Document Properties Prompt Macro Office 2010 64bit
Novice
 
Join Date: Nov 2016
Posts: 2
Vaha is on a distinguished road
Default

Hi, How would you do this with the fields, rather than document properties?
Reply With Quote
  #13  
Old 11-10-2016, 07:10 PM
macropod's Avatar
macropod macropod is online now Help with Document Properties Prompt Macro Windows 7 64bit Help with Document Properties Prompt Macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Do what, precisely?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #14  
Old 11-10-2016, 07:14 PM
Vaha Vaha is offline Help with Document Properties Prompt Macro Windows 7 64bit Help with Document Properties Prompt Macro Office 2010 64bit
Novice
 
Join Date: Nov 2016
Posts: 2
Vaha is on a distinguished road
Default

Exactly the same thing. Have a prompt to enter fields. In the advanced properties of Word are custom fields (e.g. checked by, client, date completed etc) that I would like to modify in the document with prompt dialog boxes. cheers.
Reply With Quote
  #15  
Old 11-10-2016, 08:18 PM
macropod's Avatar
macropod macropod is online now Help with Document Properties Prompt Macro Windows 7 64bit Help with Document Properties Prompt Macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Well, you could use FILLIN fields but, other than displaying whatever you input at the location where the fields are in the document, I'm not sure what that achieves that you could achieve more easily by just typing the data into the same locations without the fields - they certainly won't add anything to the document metadata
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable email security prompt mcinnes01 Outlook 1 03-17-2011 07:00 AM
Selecting the macro document lars Word VBA 0 08-19-2010 06:06 AM
Macro to put content into keywords properties? erik2000 Word VBA 3 03-05-2010 10:14 PM
Macro to export document sections to individual txt files? MJMR999 Excel Programming 0 02-18-2010 12:49 PM
document properties issues charris1980 Word 0 04-29-2009 12:49 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:34 AM.


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