Access Author/Created by from Txt file

Ed in Aus

Well-known Member
Joined
Jul 24, 2007
Messages
829
Hi everyone,

I want to be able to access who created a txt file, via vba.

I have ran out of solutions from Google and cannot figure this one out, been trying for hours.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
If you use a similar code, and adjust to your needs, see if this is any help

Code:
Sub Document_properties()
Dim filesystem As Object, myfolder As Object
Dim myfiles As Object, myfile As Object, Pastefile As Object
On Error Resume Next
Set filesystem = CreateObject("Scripting.filesystemobject")
Set myfolder = filesystem.getfolder("C:\Users\M210350\Documents\Test")
Set myfiles = myfolder.Files
Set Pastefile = filesystem.getfile("C:\Users\M210350\Documents\Test.xls")
Workbooks.Open Filename:="C:\Users\M210350\Documents\Test.xls"
A = 1
B = 1
For Each myfile In myfiles
Range("A" & A) = myfile.BuiltinDocumentProperties(1).Value 'Title
A = A + 1
Range("A" & A) = myfile.BuiltinDocumentProperties(2).Value 'Status
A = A + 1
Range("A" & A) = myfile.BuiltinDocumentProperties(3).Value 'Author
A = A + 1
Range("A" & A) = myfile.BuiltinDocumentProperties(4).Value 'Keywords
A = A + 1
Range("B" & B) = myfile.BuiltinDocumentProperties("Creation Date")
B = B + 1
Range("B" & B) = myfile.BuiltinDocumentProperties("Title")
B = B + 1
next
end sub
 
Upvote 0
Here is another method:

Code:
Set fs = CreateObject("Scripting.FileSystemObject")
SelectedFile = Application.GetOpenFilename("Excel files (*.txt), *.txt")

selectedFilePath = ""
While InStr(SelectedFile, "\") > 0
    selectedFilePath = selectedFilePath & Left(SelectedFile, InStr(SelectedFile, "\"))
    SelectedFile = Mid(SelectedFile, InStr(SelectedFile, "\") + 1)
Wend

Set oShell = CreateObject("Shell.Application")
    
Set objFolder = oShell.Namespace(selectedFilePath)
Set objFolderItem = objFolder.ParseName(SelectedFile)
    
fileCreator = objFolder.GetDetailsOf(objFolderItem, 10)
 
Upvote 0
Hi mjbeam,

Thanks for your code snippet this would be great if it was for an Excel file, but it is for a txt file and the built in document properties do not apply.

There is no value stored in these for a txt file from what i can see.

Still need to figure this one out...
 
Upvote 0
I tested this on a directory holding multiple text file, and it returned the author of each.

Hope it helps.

Code:
Sub retest_textfileproperties()
Dim sFile As Variant
Dim oShell: Set oShell = CreateObject("Shell.Application")
Dim oDir:   Set oDir = oShell.Namespace("C:\Users\M210350\Documents\Testa") 'where the directory is that stores the text files.
For Each sFile In oDir.Items
   MsgBox oDir.GetDetailsOf(sFile, 10) 'change msgbox to output where you want it.
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top