Help with macros in excel

Closed
trublood fan Posts 2 Registration date Thursday July 19, 2012 Status Member Last seen July 22, 2012 - Jul 22, 2012 at 09:40 AM
sgmpatnaik Posts 52 Registration date Tuesday April 2, 2013 Status Member Last seen November 27, 2013 - Jul 4, 2013 at 08:55 AM
Hello,

I was wondering if anyone could help me in creating a macro file for excel....I am needing to save, print, and close an excel file at a certain time of the day...that has been opened thru tasked scheduler.....the file needs to saved with the current date and time in a specific folder.

below is what I have so far does any one see what is the problem??

Public runtime
Private Sub Workbook_Open()
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\Owner.laptop\My Documents\test\ " & _
Format(Now(), "mm_dd_yyyy hh mm AMPM") 'opens wb and saves wb with current date & time
End Sub

Private Sub Start_timer()

Call StartTimer 'starts the timer when the WB opens

End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Call StopTimer 'stops the timer when WB is closed...If Excel is open, timer will continue to run without this!!

End Sub

Sub StartTimer()
runtime = Now + #12:02:00 AM# 'schedules a RunTime every 30 minutes...change as you wish
Application.OnTime runtime, Format(Now(), "mm_dd_yyy hh mm AMPM"), schedule:=True 'Calls current date and time
End Sub

Sub SaveBook()
ActiveWorkbook.Save 'Saves the WB
ActiveWorkbook.PrintOut 'prints the wb
StartTimer 'Restarts the timer
End Sub

Sub StopTimer()
On Error Resume Next
Application.OnTime runtime, Format(Now(), "mm_dd_yyy hh mm AMPM"), schedule:=False 'Stops the timer
End Sub

Private Sub close_workbook()
If Minute(Now()) = 30 Then
If Hour(Now()) = 9 Then
ActiveWorkbook.Close savechanges = True 'closes WB and saves any changes
End If
End If
End Sub




any help would be greatly appreciated.

thx


Related:

1 response

sgmpatnaik Posts 52 Registration date Tuesday April 2, 2013 Status Member Last seen November 27, 2013 45
Jul 4, 2013 at 08:55 AM
Hi Trublood

I didn't try the code but have a look which i was given a file from the download link. When you close the workbook then a new workbook will save with the format of mm_dd_yyyy hh mm AMPM

please download the file

https://dl.dropboxusercontent.com/u/75654703/For_Trublood.xlsm

if any issue please inform us

Thanks

Patnaik
0