Link to home
Start Free TrialLog in
Avatar of TadSter
TadSter

asked on

How do I add Attribute (Title, Subject, Author) to text file using VBA

I am creating a CSV file from some data in a spreadsheet using VBA. I have strict requirements about the layout and content of the file. However I need the file to hold just a bit of extra information.

In Windows Explorer I can open properties page of the CSV file and change Title, Subject and Author. If I could add an account number on the Subject line, that would be really helpful. How can I do that from VBA? I assume I will need a Windows API call. Could you help me with that?


Sub InsertAccountNum(Acct As String)
    Dim FileName As String
    FileName = "C:\Temp\Data.csv"
    
    'insert account number as subject attribute 

End Sub

Open in new window

Avatar of calacuccia
calacuccia
Flag of Belgium image

Haven't been through all the details, and did not see anything about a Subject Line ... but this might interest you if unknown

https://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/A_3509.html
Avatar of TadSter
TadSter

ASKER

Thanks, but it doesn't address my issue. I need to change the attributes of the file.
ASKER CERTIFIED SOLUTION
Avatar of calacuccia
calacuccia
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The DSOFile library from MIscrosoft allows to do what you want but only for Office files.

http://support.microsoft.com/kb/q224351/

Sample code

Sub pp()
Dim FileName As String
Dim DSO As DSOFile.OleDocumentProperties
Set DSO = New DSOFile.OleDocumentProperties
'FileName = "book2.xls"
FileName = "picture 096.jpg"
DSO.Open sfilename:=FileName
Debug.Print DSO.SummaryProperties.ApplicationName
Debug.Print DSO.SummaryProperties.Author
Debug.Print DSO.SummaryProperties.Comments
Debug.Print DSO.SummaryProperties.Subject
DSO.SummaryProperties.Comments = "my new test!!!!"   '***
Debug.Print DSO.SummaryProperties.Comments
DSO.Save
DSO.Close
End Sub

It won't work for non-office files though...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TadSter

ASKER

Wow! Ouch! That's big. Thanks for pointing me in the right direction. Thanks for the code, it's great.