write file name into text file

yinkajewole

Board Regular
Joined
Nov 23, 2018
Messages
245
how do i write the file name and path of my active workbook into a text file without putting it inside quotes i.e
c:\temp\col.xls
instead of
"c:\temp\col.xls"
 

Leith Ross

Well-known Member
Joined
Mar 17, 2008
Messages
1,878
Office Version
2010, 2007
Platform
Windows
Hello yinkajewole,

Provided the active workbook has already been saved then you can use ThisWorkbook.FullName to return the path and name of the workbook.
 
Last edited:

yinkajewole

Board Regular
Joined
Nov 23, 2018
Messages
245
Hello yinkajewole,

Provided the active workbook has already been saved then you can use ThisWorkbook.FullName to return the path and name of the workbook.
have you tried it yourself, because that was what i did initially?
 

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
5,100
Office Version
2019
Platform
Windows
I used this Macro

Code:
Sub fullname()
MsgBox (ThisWorkbook.fullname)
End Sub
and it works for me.
 

yinkajewole

Board Regular
Joined
Nov 23, 2018
Messages
245
this is the macro I'm using

Code:
Sub fullname()Dim st As String
st = "C:\Users\USER\Desktop\History.txt"
Open st For Append As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
If ActiveWorkbook.Path = "" Then
Else
Write [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , (ThisWorkbook.fullname)
End If
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
End Sub
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,575
Office Version
2010
Platform
Windows
how do i write the file name and path of my active workbook into a text file without putting it inside quotes i.e
this is the macro I'm using

Code:
Sub fullname()Dim st As String
st = "C:\Users\USER\Desktop\History.txt"
Open st For Append As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1][URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] [/URL] 
If ActiveWorkbook.Path = "" Then
Else
[B][COLOR="#FF0000"][SIZE=3]Write #1   [/SIZE][/COLOR][/B], (ThisWorkbook.fullname)
End If
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1][URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] [/URL] 
End Sub
Don't use Write #1 use Print #1 instead.
 
Last edited:

yinkajewole

Board Regular
Joined
Nov 23, 2018
Messages
245
Please, I would like to modify this code such that ThisWorkbook.fullname will remove any previous one and add the new one to the last line
Code:
Sub fullname()Dim st As Stringst = "C:\Users\USER\Desktop\History.txt"
Open st For Append As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL]   
If ActiveWorkbook.Path = "" Then
Else
Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , [B]ThisWorkbook.fullname[/B]
End If
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL]   
End Sub
 

Forum statistics

Threads
1,086,101
Messages
5,387,829
Members
402,082
Latest member
AstroSpider

Some videos you may like

This Week's Hot Topics

Top