Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Writing to a text file | Excel Programming | |||
Writing to a text file | Excel Programming | |||
Writing strings to a text file ? | Excel Programming | |||
Writing to a text file some data | Excel Programming | |||
WRITING TO A TEXT FILE WITH SPECIFIC FORMAT | Excel Programming |