Share via

Incorrect Document Properties

Anonymous
2012-01-13T21:45:56+00:00

I have a weird situation. If I open a file in Word 2007, then view the document properties by clicking on the Microsoft Office Button / Prepare / Properties, the directory where the file is located under “Location” is CORRECT. However, with the same document open, if I go to the Microsoft Office Button / Print and in the “Print What” field select “Document Properties”, the properties printed lists the directory INCORRECTLY.

What I have determined is, if I open a file using the method of: Microsoft Office Button / Open / browse to the file location and then open it, the document property print option will work. But, if I open a file from my list of “recent documents”, the printed version of the document properties will display the location of the last file I actually opened with the browse method.

Any help would be much appriciated. Many of the people I support use this function, and it works perfectly in Word 2003, but is not working on any of our Word 2007 users.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-01-24T21:08:57+00:00

Well, see how you get on with the following code. There is plenty of scope for improvement! You should really add some error checking and documentation.

Option Explicit

' Constants containing document texts

' In case you want to translate them)

Private Const strBuiltinText As String = "Built-in properties"

Private Const strFileNameText As String = "Filename"

Private Const strDirectoryText As String = "Directory"

Private Const strTemplateText As String = "Template"

Private Const strTitleText As String = "Title"

Private Const strSubjectText As String = "Subject"

Private Const strAuthorText As String = "Author"

Private Const strKeywordsText As String = "Keywords"

Private Const strCommentsText As String = "Comments"

Private Const strTimeCreatedText As String = "Creation Date"

Private Const strRevisionText As String = "Change Number"

Private Const strTimeLastSavedText As String = "Last Saved On"

Private Const strLastAuthorText As String = "Last Saved By"

Private Const strVBATotalEditText As String = "Total Editing Time (minutes)"

Private Const strTimeLastPrintedText As String = "Last Printed On"

Private Const strStatisticsSubsectionText As String = "As of Last Complete Printing (approx):-"

Private Const strPagesText As String = "Number of Pages"

Private Const strWordsText As String = "Number of Words"

Private Const strCharactersText As String = "Number of Characters"

'Private Const strCustomText As String = "Word Custom Properties"

'Private Const strServerText As String = "Server Properties"

Private Const strSeparator As String = ":" & vbTab

' The following is the UK date format used by the standard printout

Private Const strDateTimeFormat1 As String = "DDDD, DD MMMM YYYY MM/DD/YYYY hh:mm"

' Constants for when properties are missing etc.

Private Const strMissing1 As String = "(Missing)"

Private Const strDocNotSaved As String = "(Document not yet saved)"

' Constants containing the document style names that

' we will create

Private Const strSectionTitle As String = "nSectionTitle"

Private Const strPropParagraph As String = "nPropParagraph"

Private Const strSubSectionTitle As String = "nSubSectionTitle"

Private Const strPropSubParagraph As String = "nPropSubParagraph"

Sub printActiveDocumentProperties()

' Prints the ActiveDocument's properties

Dim objActiveDocument As Word.Document

Dim objPrintDocument As Word.Document

Dim objStyle As Word.Style

Set objActiveDocument = Application.ActiveDocument

Set objPrintDocument = Application.Documents.Add(Visible:=True)

Call initPrintDocument(OutputDocument:=objPrintDocument)

Call outputBuiltinProperties( _

TheDocument:=objActiveDocument, _

OutputDocument:=objPrintDocument)

objPrintDocument.PrintOut

VBA.DoEvents

objPrintDocument.Close savechanges:=WdSaveOptions.wdDoNotSaveChanges

Set objPrintDocument = Nothing

objActiveDocument.Activate

Set objActiveDocument = Nothing

End Sub

Sub initPrintDocument(OutputDocument As Word.Document)

Dim objStyle As Word.Style

OutputDocument.Content.Delete

Set objStyle = OutputDocument.Styles.Add(Name:=strSectionTitle, Type:=WdStyleType.wdStyleTypeParagraph)

With objStyle

With .Font

.Bold = True

.Size = 14

End With

With .ParagraphFormat

.Alignment = wdAlignParagraphCenter

.KeepTogether = False

.KeepWithNext = True

.SpaceAfter = 18

End With

End With

Set objStyle = OutputDocument.Styles.Add(Name:=strPropParagraph, Type:=WdStyleType.wdStyleTypeParagraph)

With objStyle

With .Font

.Bold = False

.Size = 12

End With

With .ParagraphFormat

.Alignment = wdAlignParagraphLeft

.FirstLineIndent = -96

.LeftIndent = 96

.KeepTogether = False

.KeepWithNext = True

.SpaceAfter = 0

.TabStops.Add Position:=96

End With

End With

Set objStyle = OutputDocument.Styles.Add(Name:=strSubSectionTitle, Type:=WdStyleType.wdStyleTypeParagraph)

With objStyle

With .Font

.Bold = False

.Size = 12

End With

With .ParagraphFormat

.Alignment = wdAlignParagraphLeft

.KeepTogether = False

.KeepWithNext = True

.SpaceAfter = 0

End With

End With

Set objStyle = OutputDocument.Styles.Add(Name:=strPropSubParagraph, Type:=WdStyleType.wdStyleTypeParagraph)

With objStyle

With .Font

.Bold = False

.Size = 12

End With

With .ParagraphFormat

.Alignment = wdAlignParagraphLeft

.FirstLineIndent = -72

.LeftIndent = 96

.KeepTogether = False

.KeepWithNext = True

.SpaceAfter = 0

.TabStops.Add Position:=96

End With

End With

Set objStyle = Nothing

End Sub

Sub outputBuiltinProperties(TheDocument As Word.Document, _

OutputDocument As Word.Document)

outputSectionTitle _

OutputDocument:=OutputDocument, _

SectionTitle:=strBuiltinText

outputProperty _

OutputDocument:=OutputDocument, _

PropertyName:=strFileNameText, _

PropertyValue:=TheDocument.Name, _

ParagraphStyle:=strPropParagraph

If TheDocument.path = "" Then

outputProperty _

OutputDocument:=OutputDocument, _

PropertyName:=strDirectoryText, _

PropertyValue:=strDocNotSaved, _

ParagraphStyle:=strPropParagraph

Else

outputProperty _

OutputDocument:=OutputDocument, _

PropertyName:=strDirectoryText, _

PropertyValue:=TheDocument.path, _

ParagraphStyle:=strPropParagraph

End If

outputProperty _

OutputDocument:=OutputDocument, _

PropertyName:=strTemplateText, _

PropertyValue:=TheDocument.AttachedTemplate.FullName, _

ParagraphStyle:=strPropParagraph

outputBuiltinProperty _

TheDocument:=TheDocument, _

OutputDocument:=OutputDocument, _

PropertyName:=strTitleText, _

PropertyID:=WdBuiltInProperty.wdPropertyTitle

outputBuiltinProperty _

TheDocument:=TheDocument, _

OutputDocument:=OutputDocument, _

PropertyName:=strSubjectText, _

PropertyID:=WdBuiltInProperty.wdPropertySubject

outputBuiltinProperty _

TheDocument:=TheDocument, _

OutputDocument:=OutputDocument, _

PropertyName:=strAuthorText, _

PropertyID:=WdBuiltInProperty.wdPropertyAuthor

outputBuiltinProperty _

TheDocument:=TheDocument, _

OutputDocument:=OutputDocument, _

PropertyName:=strKeywordsText, _

PropertyID:=WdBuiltInProperty.wdPropertyKeywords

outputBuiltinProperty _

TheDocument:=TheDocument, _

OutputDocument:=OutputDocument, _

PropertyName:=strCommentsText, _

PropertyID:=WdBuiltInProperty.wdPropertyComments

outputBuiltinDateTimeProperty _

TheDocument:=TheDocument, _

OutputDocument:=OutputDocument, _

PropertyName:=strTimeCreatedText, _

PropertyID:=WdBuiltInProperty.wdPropertyTimeCreated

outputBuiltinDateTimeProperty _

TheDocument:=TheDocument, _

OutputDocument:=OutputDocument, _

PropertyName:=strRevisionText, _

PropertyID:=WdBuiltInProperty.wdPropertyRevision

outputBuiltinDateTimeProperty _

TheDocument:=TheDocument, _

OutputDocument:=OutputDocument, _

PropertyName:=strTimeLastSavedText, _

PropertyID:=WdBuiltInProperty.wdPropertyTimeLastSaved

outputBuiltinProperty _

TheDocument:=TheDocument, _

OutputDocument:=OutputDocument, _

PropertyName:=strLastAuthorText, _

PropertyID:=WdBuiltInProperty.wdPropertyLastAuthor

outputBuiltinProperty _

TheDocument:=TheDocument, _

OutputDocument:=OutputDocument, _

PropertyName:=strVBATotalEditText, _

PropertyID:=WdBuiltInProperty.wdPropertyVBATotalEdit

outputBuiltinDateTimeProperty _

TheDocument:=TheDocument, _

OutputDocument:=OutputDocument, _

PropertyName:=strTimeLastPrintedText, _

PropertyID:=WdBuiltInProperty.wdPropertyTimeLastPrinted

outputSubSectionTitle _

OutputDocument:=OutputDocument, _

SubSectionTitle:=strStatisticsSubsectionText

outputBuiltinSubProperty _

TheDocument:=TheDocument, _

OutputDocument:=OutputDocument, _

PropertyName:=strPagesText, _

PropertyID:=WdBuiltInProperty.wdPropertyPages

outputBuiltinSubProperty _

TheDocument:=TheDocument, _

OutputDocument:=OutputDocument, _

PropertyName:=strWordsText, _

PropertyID:=WdBuiltInProperty.wdPropertyWords

outputBuiltinSubProperty _

TheDocument:=TheDocument, _

OutputDocument:=OutputDocument, _

PropertyName:=strCharactersText, _

PropertyID:=WdBuiltInProperty.wdPropertyCharacters

End Sub

Sub outputBuiltinProperty(TheDocument As Word.Document, _

OutputDocument As Word.Document, _

PropertyName As String, _

PropertyID As WdBuiltInProperty)

Dim s As String

On Error Resume Next

s = strMissing1

s = TheDocument.BuiltInDocumentProperties(PropertyID)

Err.Clear

On Error GoTo 0

outputProperty _

OutputDocument:=OutputDocument, _

PropertyName:=PropertyName, _

PropertyValue:=s, _

ParagraphStyle:=strPropParagraph

End Sub

Sub outputBuiltinSubProperty(TheDocument As Word.Document, _

OutputDocument As Word.Document, _

PropertyName As String, _

PropertyID As WdBuiltInProperty)

Dim s As String

On Error Resume Next

s = strMissing1

s = TheDocument.BuiltInDocumentProperties(PropertyID)

Err.Clear

On Error GoTo 0

outputProperty _

OutputDocument:=OutputDocument, _

PropertyName:=PropertyName, _

PropertyValue:=s, _

ParagraphStyle:=strPropSubParagraph

End Sub

Sub outputBuiltinDateTimeProperty(TheDocument As Word.Document, _

OutputDocument As Word.Document, _

PropertyName As String, _

PropertyID As WdBuiltInProperty)

Dim s As String

On Error Resume Next

s = strMissing1

s = Format(TheDocument.BuiltInDocumentProperties(PropertyID), strDateTimeFormat1)

Err.Clear

On Error GoTo 0

outputProperty _

OutputDocument:=OutputDocument, _

PropertyName:=PropertyName, _

PropertyValue:=s, _

ParagraphStyle:=strPropParagraph

End Sub

Sub outputProperty(OutputDocument As Word.Document, _

PropertyName As String, _

PropertyValue As String, _

ParagraphStyle As String)

Dim r As Word.Range

Set r = OutputDocument.Content

r.SetRange OutputDocument.Content.End, OutputDocument.Content.End

r.Style = ParagraphStyle

Set r = Nothing

OutputDocument.Content.InsertAfter PropertyName & strSeparator & PropertyValue

OutputDocument.Content.InsertParagraphAfter

End Sub

Sub outputSectionTitle(OutputDocument As Word.Document, _

SectionTitle As String)

Dim r As Word.Range

Set r = OutputDocument.Content

r.SetRange OutputDocument.Content.End, OutputDocument.Content.End

r.Style = strSectionTitle

Set r = Nothing

OutputDocument.Content.InsertAfter SectionTitle

OutputDocument.Content.InsertParagraphAfter

End Sub

Sub outputSubSectionTitle(OutputDocument As Word.Document, _

SubSectionTitle As String)

Dim r As Word.Range

Set r = OutputDocument.Content

r.SetRange OutputDocument.Content.End, OutputDocument.Content.End

r.Style = strSubSectionTitle

Set r = Nothing

OutputDocument.Content.InsertAfter SubSectionTitle

OutputDocument.Content.InsertParagraphAfter

End Sub

Was this answer helpful?

0 comments No comments

10 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-01-17T20:45:51+00:00

    I am having the same problem.  It seems like the file is being stored within a temporary location under the user's profile when attempting to print after retrieving the document via "Recent Document" but is not using the location of the original document.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-01-17T20:35:29+00:00

    Additional note.... just tested this in Word 10, same exact problem. Will not print the correct document properties even though the document properties are correct.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-01-14T18:53:18+00:00

    Only one copy of the file, and the files have not been moved to another location. Yes, we are on a network. But I can also create this scenario with local files as well. 

    Its not just one case of incorrect information. I can create this same scenario over and over again with different files in different locations, and on different computers. The printed document properties always shows the directory location of the last file opened by using a method other than using the recent documents. I hope I am making sense... this is hard to explain. Yesterday I even had a user that opened a document from an email, review and then closed the file. Then, she opened a different file from her recent document list  that she had been working on. When she printed the document properties of this file, the file directory location that printed out on the document property page showed the file was stored in her local temp folder.

    Its like Word is caching document properties, but only when you do the "print" properties function. I can go to the viewable properties and it always shows the correct location.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2012-01-14T17:05:06+00:00

    Have you saved multiple copies of these files in different locations?

    If you open the document from ‘Recent files’ does it show the new location in document properties?

    Are the computers on network? Are the files located in network location?

    Was this answer helpful?

    0 comments No comments