ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   writing to text file (https://www.excelbanter.com/excel-programming/393303-writing-text-file.html)

ADK

writing to text file
 
ThisWorkbook.Name returns the name of the file name....but with .xls

Is there a way to only return the file name with the extension?


UserName = Environ("USERNAME")
CpuName = Environ("COMPUTERNAME")
WhatOffice = Environ("USERDOMAIN")
MyFullName = ThisWorkbook.FullName
Contents:=True, UserInterfaceOnly:=True
Open "W:\PL10\PDSRlogs" & "\usage-" & ThisWorkbook.Name & ".log" For
Append As #1
Print #1, UserName, WhatOffice, CpuName, Now, MyFullName
'Print #1, Application.UserName, Now
Close #1



Vergel Adriano

writing to text file
 
Maybe the Replace function can help you.

Replace(thisworkbook.Name, ".xls", ".log", 1, -1, vbTextCompare)


--
Hope that helps.

Vergel Adriano


"ADK" wrote:

ThisWorkbook.Name returns the name of the file name....but with .xls

Is there a way to only return the file name with the extension?


UserName = Environ("USERNAME")
CpuName = Environ("COMPUTERNAME")
WhatOffice = Environ("USERDOMAIN")
MyFullName = ThisWorkbook.FullName
Contents:=True, UserInterfaceOnly:=True
Open "W:\PL10\PDSRlogs" & "\usage-" & ThisWorkbook.Name & ".log" For
Append As #1
Print #1, UserName, WhatOffice, CpuName, Now, MyFullName
'Print #1, Application.UserName, Now
Close #1




Keith74

writing to text file
 
Hi

This seems to do the job (assuming the last 4 chars are the file
extension)

left(thisworkbook.Name,len(thisworkbook.Name)-4)

hth

Keith


Tim

writing to text file
 
Msgbox Split(ThisWorkbook.Name, ".")(0)

Tim


"ADK" wrote in message
...
ThisWorkbook.Name returns the name of the file name....but with .xls

Is there a way to only return the file name with the extension?


UserName = Environ("USERNAME")
CpuName = Environ("COMPUTERNAME")
WhatOffice = Environ("USERDOMAIN")
MyFullName = ThisWorkbook.FullName
Contents:=True, UserInterfaceOnly:=True
Open "W:\PL10\PDSRlogs" & "\usage-" & ThisWorkbook.Name & ".log" For
Append As #1
Print #1, UserName, WhatOffice, CpuName, Now, MyFullName
'Print #1, Application.UserName, Now
Close #1




Dave Peterson

writing to text file
 
Watch out if the filename contains dots.

book1.generated.by.tim.on.2007.07.13.xls



Tim wrote:

Msgbox Split(ThisWorkbook.Name, ".")(0)

Tim

"ADK" wrote in message
...
ThisWorkbook.Name returns the name of the file name....but with .xls

Is there a way to only return the file name with the extension?


UserName = Environ("USERNAME")
CpuName = Environ("COMPUTERNAME")
WhatOffice = Environ("USERDOMAIN")
MyFullName = ThisWorkbook.FullName
Contents:=True, UserInterfaceOnly:=True
Open "W:\PL10\PDSRlogs" & "\usage-" & ThisWorkbook.Name & ".log" For
Append As #1
Print #1, UserName, WhatOffice, CpuName, Now, MyFullName
'Print #1, Application.UserName, Now
Close #1


--

Dave Peterson

Charlie

writing to text file
 
That method is slick but not foolproof: It is possible to have dots in the
filename as well as folder names. There are some file system functions you
can use

' FileSystemObject requires Microsoft Scripting Runtime Library

Public FSO As New FileSystemObject

If Right(FileName, 1) < "\" Then FileName = FSO.GetBaseName(FileName)
FileType = "." & FSO.GetExtensionName(FileName)

....etc.


"Tim" wrote:

Msgbox Split(ThisWorkbook.Name, ".")(0)

Tim


"ADK" wrote in message
...
ThisWorkbook.Name returns the name of the file name....but with .xls

Is there a way to only return the file name with the extension?


UserName = Environ("USERNAME")
CpuName = Environ("COMPUTERNAME")
WhatOffice = Environ("USERDOMAIN")
MyFullName = ThisWorkbook.FullName
Contents:=True, UserInterfaceOnly:=True
Open "W:\PL10\PDSRlogs" & "\usage-" & ThisWorkbook.Name & ".log" For
Append As #1
Print #1, UserName, WhatOffice, CpuName, Now, MyFullName
'Print #1, Application.UserName, Now
Close #1





Rick Rothstein \(MVP - VB\)

writing to text file
 
Msgbox Split(ThisWorkbook.Name, ".")(0)

Watch out if the filename contains dots.

book1.generated.by.tim.on.2007.07.13.xls


This should work then...

MsgBox Left$(ThisWorkbook.Name, InStrRev(ThisWorkbook.Name, ".") - 1)

Rick

ADK

writing to text file
 
This one will work for what I need....thanks


"Keith74" wrote in message
oups.com...
Hi

This seems to do the job (assuming the last 4 chars are the file
extension)

left(thisworkbook.Name,len(thisworkbook.Name)-4)

hth

Keith





All times are GMT +1. The time now is 07:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com