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?
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
ASKER
Thanks, but it doesn't address my issue. I need to change the attributes of the file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.OleDocumentPropert ies
Set DSO = New DSOFile.OleDocumentPropert ies
'FileName = "book2.xls"
FileName = "picture 096.jpg"
DSO.Open sfilename:=FileName
Debug.Print DSO.SummaryProperties.Appl icationNam e
Debug.Print DSO.SummaryProperties.Auth or
Debug.Print DSO.SummaryProperties.Comm ents
Debug.Print DSO.SummaryProperties.Subj ect
DSO.SummaryProperties.Comm ents = "my new test!!!!" '***
Debug.Print DSO.SummaryProperties.Comm ents
DSO.Save
DSO.Close
End Sub
It won't work for non-office files though...
http://support.microsoft.com/kb/q224351/
Sample code
Sub pp()
Dim FileName As String
Dim DSO As DSOFile.OleDocumentPropert
Set DSO = New DSOFile.OleDocumentPropert
'FileName = "book2.xls"
FileName = "picture 096.jpg"
DSO.Open sfilename:=FileName
Debug.Print DSO.SummaryProperties.Appl
Debug.Print DSO.SummaryProperties.Auth
Debug.Print DSO.SummaryProperties.Comm
Debug.Print DSO.SummaryProperties.Subj
DSO.SummaryProperties.Comm
Debug.Print DSO.SummaryProperties.Comm
DSO.Save
DSO.Close
End Sub
It won't work for non-office files though...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wow! Ouch! That's big. Thanks for pointing me in the right direction. Thanks for the code, it's great.
https://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/A_3509.html