View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Melanie Breden Melanie Breden is offline
external usenet poster
 
Posts: 88
Default deleting last 4 characters from file name

Hi Hans,

Hans schrieb:
I have the following macro for saving a file under the
existing name with "For Reporting" added to it:

Sub SaveAsReporting()
Dim stOldName As String
Dim stNewName As String
stOldName = ThisWorkbook.FullName
stNewName = stOldName & " For Reporting"
ActiveWorkbook.SaveAs stNewName
End Sub

However, the new name also includes the extension ".xls"
("filename.xls For Reporting") and I don't like that. Is
there a simple way to save the file without the ".xls"?


starting from Excel2000 you can use the Replace function:

stOldName = VBA.Replace(ThisWorkbook.FullName, ".xls", "")


or:

ActiveWorkbook.SaveAs Replace(ThisWorkbook.FullName, ".xls", "") & _
" For Reporting"

--
Mit freundlichen Grüssen

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)