Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically extract File Description Comments 1

Status
Not open for further replies.

rockfish12

Technical User
Feb 12, 2002
31
0
0
US
Is there a way, using VBA, to extract any/all of the File Description elements for a given file?

To further clarify, in Win2K - and maybe other Win OS's (?) - , when you right-click on a file to get its properties, and click on the Summary tab, there are a number of Description elements that users can type stuff in, including Title, Subject, Category, Keyword, Comments, etc...

I have some text files where a user has entered values in the Comments portion of the File Description. Can I get at these programmatically using VBA? I'm trying to write the name of the file and the associated Comments to an Access table.
 
The following example assumes that you are trying to get these properties from a document that is not currently open:

Code:
Sub Test()
   Call GetAttributes("C:\MyTestFile.doc")
End Sub


Sub GetAttributes(strFileName As String)
   Dim objApp        As Word.Application
   Dim strProps      As String
   Dim strRevNum     As String
   
   Set objApp = CreateObject("Word.Application")
   objApp.Visible = False
   objApp.DisplayAlerts = False
   objApp.Documents.Open FileName:=strFileName, _
      ConfirmConversions:=False, ReadOnly:=True, AddToRecentFiles:=False, _
      PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
      WritePasswordDocument:="", WritePasswordTemplate:="", _
      Format:=wdOpenFormatAuto
    
   For Each prop In objApp.ActiveDocument.BuiltInDocumentProperties
      strProps = strProps & prop.Name & "= "
      On Error Resume Next
      strProps = strProps & prop.Value
      strProps = strProps & Chr(10)
   Next
   MsgBox strProps
   
   strRevNum = "Revision Number = " & objApp.ActiveDocument.BuiltInDocumentProperties(wdPropertyRevision)
   MsgBox strRevNum
Code:
   'the enumerated properties for BuiltInDocumentProperties are:
   '   wdPropertyAppName
   '   wdPropertyAuthor
   '   wdPropertyBytes
   '   wdPropertyCategory
   '   wdPropertyCharacters
   '   wdPropertyCharsWSpaces
   '   wdPropertyComments
   '   wdPropertyCompany
   '   wdPropertyFormat
   '   wdPropertyHiddenSlides
   '   wdPropertyHyperlinkBase
   '   wdPropertyKeywords
   '   wdPropertyLastAuthor
   '   wdPropertyLines
   '   wdPropertyManager
   '   wdPropertyMMClips
   '   wdPropertyNotes
   '   wdPropertyPages
   '   wdPropertyParas
   '   wdPropertyRevision
   '   wdPropertySecurity
   '   wdPropertySlides
   '   wdPropertySubject
   '   wdPropertyTemplate
   '   wdPropertyTimeCreated
   '   wdPropertyTimeLastPrinted
   '   wdPropertyTimeLastSaved
   '   wdPropertyTitle
   '   wdPropertyVBATotalEdit
   '   wdPropertyWords
Code:
   objApp.Documents.Close SaveChanges:=False
   objApp.Quit
   Set objApp = Nothing
End Sub
 
Thanks for your help.

I should have specified that all of the files are plain text files, in .txt format. I tried saving one of them as a Word Document, but unfortunately, it looks like Word loses the comments in the conversion.

Is there any way to either get Word to preserve these comments, or is there a way to run VBA that will get comments from a plain .txt file?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top