Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default deleting last 4 characters from file name

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"?

Hans
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default deleting last 4 characters from file name

Hi Hans,

Try this adaptation:

Sub SaveAsReporting()
Dim stOldName As String
Dim stNewName As String
Dim stPartName As String

stOldName = ThisWorkbook.FullName
stPartName = Left(stOldName, Len(stOldName) - 4)
stNewName = stPartName & " For Reporting.xls"
ActiveWorkbook.SaveAs stNewName
End Sub

---
Regards,
Norman

"Hans" wrote in message
...
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"?

Hans



  #3   Report Post  
Posted to microsoft.public.excel.programming
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)

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default deleting last 4 characters from file name

try something like:

stOldName = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4)


Hans wrote:
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"?

Hans


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default deleting last 4 characters from file name

Hello Norman

It works. Thanks!

regards,
Hans
-----Original Message-----
Hi Hans,

Try this adaptation:

Sub SaveAsReporting()
Dim stOldName As String
Dim stNewName As String
Dim stPartName As String

stOldName = ThisWorkbook.FullName
stPartName = Left(stOldName, Len(stOldName) - 4)
stNewName = stPartName & " For Reporting.xls"
ActiveWorkbook.SaveAs stNewName
End Sub

---
Regards,
Norman

"Hans" wrote in

message
...
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"?

Hans



.

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
Deleting LF Characters in cells BillH Excel Worksheet Functions 10 March 19th 08 10:19 PM
Deleting Characters Vinny0128 Excel Discussion (Misc queries) 2 May 7th 07 03:19 AM
Deleting rows with 11+ characters. Sinner Excel Discussion (Misc queries) 0 March 29th 07 04:53 PM
Deleting characters that are not numbers jermsalerms Excel Discussion (Misc queries) 4 January 12th 06 08:06 PM
Deleting 3 Text characters from the right Helen Excel Worksheet Functions 7 April 26th 05 04:17 PM


All times are GMT +1. The time now is 06:18 AM.

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

About Us

"It's about Microsoft Excel"