Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ADK ADK is offline
external usenet poster
 
Posts: 89
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 145
Default 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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default 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




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default 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
  #8   Report Post  
Posted to microsoft.public.excel.programming
ADK ADK is offline
external usenet poster
 
Posts: 89
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing to a text file scantor145[_9_] Excel Programming 6 June 30th 05 08:23 PM
Writing to a text file Rachel Curran Excel Programming 0 October 8th 04 09:44 AM
Writing strings to a text file ? Dan Thompson Excel Programming 3 September 23rd 04 07:17 PM
Writing to a text file some data Tom Ogilvy Excel Programming 0 September 9th 04 04:25 PM
WRITING TO A TEXT FILE WITH SPECIFIC FORMAT [email protected] Excel Programming 2 December 27th 03 05:04 AM


All times are GMT +1. The time now is 01:48 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"