Add Filename to the txt file

maclachlan19

Board Regular
Joined
Jul 8, 2013
Messages
53
I have a small script that logs when a user opens an excel file.
Currently the username and date/time are populated in the txt file. I would like to add filename to the txt file, but not sure how. Thanks
Rich (BB code):
Private Sub Workbook_Open()
On Error GoTo errhandler:
Open "D:\Reports-Service\Old Reports\Log Files\ELR Analysis.log" For Append As #1 
Print #1 , Application.UserName, Now
Close #1 
Exit Sub
errhandler:
MsgBox "Log file not saved"


End Sub
 
Last edited by a moderator:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I'm assuming that you want to add the filename on the same line. If so, try...

Code:
Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , Application.UserName, Now, ThisWorkbook.Name

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,147
Members
453,021
Latest member
Justyna P

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