#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Help Needed

Hi All,


I have a strange problem (or may be I do not understand it well)


I am trying to run a code on the Before Save event which would delete
sheet named as todays date (The function here will convert date in a
string format t be saved) .


The problem is when I press the Alt Save button it runs fine and
deletes the sheet named "5-2-2007" but when I save the file using an
Activex Button that I created on the sheet it does't deletes the
sheet.


The Button has the code:


activeworkbook.save


following is the code I have .....


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)


Dim NameOfCurrentSheet As String


NameOfCurrentSheet = NameOfToday(Now())
Sheets(NameOfCurrentSheet).Delete


End Sub


Function NameOfToday(d As Date) As String
Day1 = Day(d)
Month1 = Month(d)
Year1 = Year(d)


NameOfToday = Day1 & "-" & Month1 & "-" & Year1
End Function


Thanking you all in advance.


Regards
Ankur Richard
www.xlmacros.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Help Needed

Why not just refer to it by its index number?



"ankur" wrote:

Hi All,


I have a strange problem (or may be I do not understand it well)


I am trying to run a code on the Before Save event which would delete
sheet named as todays date (The function here will convert date in a
string format t be saved) .


The problem is when I press the Alt Save button it runs fine and
deletes the sheet named "5-2-2007" but when I save the file using an
Activex Button that I created on the sheet it does't deletes the
sheet.


The Button has the code:


activeworkbook.save


following is the code I have .....


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)


Dim NameOfCurrentSheet As String


NameOfCurrentSheet = NameOfToday(Now())
Sheets(NameOfCurrentSheet).Delete


End Sub


Function NameOfToday(d As Date) As String
Day1 = Day(d)
Month1 = Month(d)
Year1 = Year(d)


NameOfToday = Day1 & "-" & Month1 & "-" & Year1
End Function


Thanking you all in advance.


Regards
Ankur Richard
www.xlmacros.com


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Help Needed

Why not use the index number?

idx = ActiveSheet.Index
Worksheets(idx).Delete

You can substitute your sheet name or number for "ActiveSheet", or if you
know the index number, just use the one line with worksheets() and fill in
the index number.

"ankur" wrote:

Hi All,


I have a strange problem (or may be I do not understand it well)


I am trying to run a code on the Before Save event which would delete
sheet named as todays date (The function here will convert date in a
string format t be saved) .


The problem is when I press the Alt Save button it runs fine and
deletes the sheet named "5-2-2007" but when I save the file using an
Activex Button that I created on the sheet it does't deletes the
sheet.


The Button has the code:


activeworkbook.save


following is the code I have .....


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)


Dim NameOfCurrentSheet As String


NameOfCurrentSheet = NameOfToday(Now())
Sheets(NameOfCurrentSheet).Delete


End Sub


Function NameOfToday(d As Date) As String
Day1 = Day(d)
Month1 = Month(d)
Year1 = Year(d)


NameOfToday = Day1 & "-" & Month1 & "-" & Year1
End Function


Thanking you all in advance.


Regards
Ankur Richard
www.xlmacros.com


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 Rows With Non-Needed Data between Needed Data Daren Excel Worksheet Functions 2 September 30th 08 06:47 PM
More Help Needed! sferguson Excel Discussion (Misc queries) 3 April 2nd 08 08:46 PM
If/AND/OR help needed.. Anthony Slater Excel Discussion (Misc queries) 5 April 25th 05 05:41 PM
xla/xls help needed! MattShoreson[_10_] Excel Programming 1 January 13th 04 09:24 PM
help needed BDCC Excel Programming 1 August 11th 03 03:24 PM


All times are GMT +1. The time now is 09:40 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"