View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Daniel Daniel is offline
external usenet poster
 
Posts: 354
Default Automate Monthly Task

Here's what happens... It generates all of the reports, for example, 02-01-08
thru 02-29-08. Once it's finished the Master Template is closed (without my
doing) and the last day of the month is open, in this example 02-29-08. There
is a command button in the workbook for 02-29-08. If I exit without saving in
02-29-08 the command button won't be there.

Not sure if that makes any sense.

"Rick Rothstein (MVP - VB)" wrote:

Just so I am clear... where is the last day of the month remaining at (which
file, which sheet, which cell)?

Rick


"Daniel" wrote in message
...
It still does the same thing - I'm going to play with the code a little
and
see what I can do or mess up =]. Again, thanks for your help. This will
save
me a lot of time.

- Daniel

"Rick Rothstein (MVP - VB)" wrote:

I think if you add this statement...

.Value = ""

immediately **before** the End With statement, it will clear out the last
date from A1 on your template file.

Rick


"Daniel" wrote in message
...
Thank you so much. I noticed one thing after few tests - after it
creates
all
of the workbooks it closes the master template and is left on the last
day
of
the month. Not a big issue, but the last day also has a Comman Button
on
it.

- Daniel

"Rick Rothstein (MVP - VB)" wrote:

I think the code below will do what you have asked. By the way, one
note
on
this code... I made a small change (correction) to what I posted
earlier...
the month you type into the InputBox is to be the month you want to
produce
your files for, **not** the current month. This will allow you to
generate
any month, or as many months, in advance as you want to. Oh, and the
code
I
used for hiding the CommandButton assumes the CommandButton is an
ActiveX
one, **not** one from the Form's toolbar.

Sub SaveMonthlyDays()
Dim X As Long
Dim Mnth As Long
Dim Dte As Date
Dim Path As String
Path = "//rich5019/Common/West Region/SLC114/SLC CUT TIME REPORT/"
Mnth = InputBox("Enter the month as a number", "Get Month")
With Worksheets(1).Range("A1")
For X = 1 To Day(DateSerial(Year(Now) - _
(Mnth < Month(Now)), Mnth, 0))
If Weekday(DateSerial(Year(Now) - _
(Mnth < Month(Now)), Mnth, X), vbMonday) < 6 Then
Dte = DateSerial(Year(Now) - (Mnth < Month(Now)), Mnth, X)
.Value = Dte
.NumberFormat = "dd/mm/yyyy"
Worksheets(1).OLEObjects("CommandButton1").Visible = False
ThisWorkbook.SaveAs Path & Format(Dte, "dd-mm-yy")
End If
Next
Worksheets(1).OLEObjects("CommandButton1").Visible = True
End With
End Sub

Rick