Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Save Workbook with existing Name in the Folder

Hi all, I have code below which save the current worksheet as
separate workbook in folder "Record"

Private Sub CommandButton17_Click()
Me.Select
Me.Copy
ActiveWorkbook.SaveAs Filename:="C:\Documents\Record\" & Left(Range
("A13").Value, Len(Range("A13").Value) - 5) & " ( " & Range
("D23").Value & " )" & ".xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
ActiveWindow.Close
End Sub

I need some code to put in above macro which should check first if
there is any name of existing workbook in the folder which is same of
new workbook which is going to be save in that folder and if the names
are same then macro should put like 1 , 2 at the end of new workbook
name so it can be save. I want the same names but want to make them
different by putting numbers at the end of the workbookname like 1 ,
2 , 3 ..... etc. I hope i was able to explain my question. Please
can any friend can help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 915
Default Save Workbook with existing Name in the Folder

K wrote:
Hi all, I have code below which save the current worksheet as
separate workbook in folder "Record"

Private Sub CommandButton17_Click()
Me.Select
Me.Copy
ActiveWorkbook.SaveAs Filename:="C:\Documents\Record\" & Left(Range
("A13").Value, Len(Range("A13").Value) - 5) & " ( " & Range
("D23").Value & " )" & ".xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
ActiveWindow.Close
End Sub

I need some code to put in above macro which should check first if
there is any name of existing workbook in the folder which is same of
new workbook which is going to be save in that folder and if the names
are same then macro should put like 1 , 2 at the end of new workbook
name so it can be save. I want the same names but want to make them
different by putting numbers at the end of the workbookname like 1 ,
2 , 3 ..... etc. I hope i was able to explain my question. Please
can any friend can help



Try this (untested) modification:

Private Sub CommandButton17_Click()
dim FileBase as string
dim TryName as String
dim j as long

Me.Select
Me.Copy

FileBase = "C:\Documents\Record\" & Left(Range
("A13").Value, Len(Range("A13").Value) - 5) & " ( " & Range
("D23").Value & " )"

j = -1
Do
j = j + 1
If j = 0 then
TryName = FileBase & ".xslm"
Else
TryName = FileBase & j & ".xslm"
End If
Loop Until Dir(TryName) = ""

ActiveWorkbook.SaveAs Filename:=TryName, FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
ActiveWindow.Close
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Save Workbook with existing Name in the Folder

thanks lot smartin, man you are genious. The only thing I changed in
your macro was the file format which is "xlsm" and its working
superb. I been really looking forward for the answer as I am doing a
project and I needed this for that. Thanks again man

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 915
Default Save Workbook with existing Name in the Folder

K wrote:
thanks lot smartin, man you are genious. The only thing I changed in
your macro was the file format which is "xlsm" and its working
superb. I been really looking forward for the answer as I am doing a
project and I needed this for that. Thanks again man


Good to know. Thanks for pointing out my typo (^:
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
How to save existing Workbook with a new new name, without changingthe open Workbook name? [email protected] Excel Programming 7 February 3rd 08 03:35 AM
Force a Readonly Workbook to save to a different folder Charlotte Howard Excel Discussion (Misc queries) 6 August 23rd 06 04:41 PM
save workbook created from templete to a specific folder imh Excel Discussion (Misc queries) 1 June 2nd 06 11:29 PM
code to save the whole folder with a workbook Tim Excel Programming 2 June 30th 05 11:41 PM
code to save the whole folder in which is the workbook Tim Excel Programming 4 June 30th 05 11:40 PM


All times are GMT +1. The time now is 11:22 PM.

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"