By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,829 Members | 673 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,829 IT Pros & Developers. It's quick & easy.

Custom Document Properties

P: 2
I'm developing a database to create a hyperlinked index of files in a folder. I'm trying to get document properties for all files in a folder. Properties like FileName, Author, and Tags. Using VBA how can I grab document property information from each file and store it in a table. The documents are Word documents.
Thanks
Jun 21 '17 #1
Share this Question
Share on Google+
2 Replies


ADezii
Expert 5K+
P: 8,623
You can grab Built-In or Custom Properties of a Word Document by accessing the BuiltInDocumentProperties and/or CustomDocumentProperties of a Word Document Object. Typical Built-In Properties would be:
Expand|Select|Wrap|Line Numbers
  1. 01            Title
  2. 02            Subject
  3. 03            Author
  4. 04            Keywords
  5. 05            Comments
  6. 06            Template
  7. 07            Last author
  8. 08            Revision number
  9. 09            Application name
  10. 10            Last print date
  11. 11            Creation date
  12. 12            Last save time
  13. 13            Total editing time
  14. 14            Number of pages
  15. 15            Number of words
  16. 16            Number of characters
  17. 17            Security
  18. 18            Category
  19. 19            Format
  20. 20            Manager
  21. 21            Company
  22. 22            Number of bytes
  23. 23            Number of lines
  24. 24            Number of paragraphs
  25. 25            Number of slides
  26. 26            Number of notes
  27. 27            Number of hidden Slides
  28. 28            Number of multimedia clips
  29. 29            Hyperlink base
  30. 30            Number of characters (with spaces)
  31. 31            Content type
  32. 32            Content status
  33. 33            Language
  34. 34            Document version
Jun 21 '17 #2

PhilOfWalton
Expert 100+
P: 1,430
Interesting question, but this might get you started

These first 2 routines get the names of all .doc & .docx in a named folder and all subfolders.

In this case my main folder is called "E:\Phil Data\Word Documents\BOATS\"
Note the final "\"

Expand|Select|Wrap|Line Numbers
  1. Function GetWordFiles(HostFolder As String)
  2. '?GetWordFiles("E:\Phil Data\Word Documents\BOATS\")
  3.     ' Routine to get all files & foldere in host folder
  4.  
  5.     Dim FileSystem As Object
  6.  
  7.     Set FileSystem = CreateObject("Scripting.FileSystemObject")
  8.     DoFolder FileSystem.GetFolder(HostFolder)
  9.  
  10. End Function
  11.  
  12. Sub DoFolder(Folder)
  13.  
  14.     Dim SubFolder As Variant
  15.     Dim File As Variant
  16.  
  17.     For Each SubFolder In Folder.SubFolders
  18.         DoFolder SubFolder
  19.     Next
  20.  
  21.     For Each File In Folder.Files
  22.         If right(File.Name, 5) = ".docx" Or right(File.Name, 4) = ".doc" Then   ' For whaterver files you need
  23.             Debug.Print File.Name
  24.             fEnumProps Folder & "\" & File.Name
  25.             Debug.Print "*******************************************************"
  26.             Debug.Print
  27.         End If
  28.     Next
  29.  
  30. End Sub
  31.  
The next bit of code displays about 25 lines of the document's properties. Obviously you must select the ones you want and load them to your table.

Expand|Select|Wrap|Line Numbers
  1. Function fEnumProps(strInFile As String)
  2.  
  3.     Dim objWord As Object, objDocProps As Object
  4.     Dim i As Integer
  5.  
  6.     On Error Resume Next
  7.  
  8.     Set objWord = CreateObject("Word.Application")
  9.  
  10.     With objWord
  11.         .Documents.Open strInFile
  12.         Set objDocProps = objWord.ActiveDocument.BuiltInDocumentProperties
  13.  
  14.         For i = 0 To objDocProps.Count - 1
  15.             Debug.Print objDocProps(i).Name, objDocProps(i).Value
  16.         Next i
  17.     End With
  18.  
  19.     objWord.Application.Quit savechanges:=False
  20.     Set objWord = Nothing
  21.  
  22. End Function
  23.  
Phil
Jun 21 '17 #3

Post your reply

Sign in to post your reply or Sign up for a free account.