PC Review


Reply
 
 
LiAD
Guest
Posts: n/a
 
      27th Jul 2009
Hi,

I am trying to use this code to hide the formula bars, menus etc and save
and close a file after a certain time has passed, but i can't get it to run.
Unfortunately I have reached the limit of what i know to try to fix the
problem and get it to run. It errors on this line (line is in two places and
both error).

----Application.OnTime RunWhen, "SaveAndClose", , False ------

Any ideas how I can fix this?
Thanks
LiAD

Entered as a workbook code

Application.OnTime RunWhen, "SaveAndClose", , False

Private mFormulaBar

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim oCB As CommandBar
On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
For Each oCB In Application.CommandBars
oCB.Enabled = True
Next oCB

Application.DisplayFormulaBar = mFormulaBar

Application.Quit
End Sub

Private Sub Workbook_Open()
Dim oCB As CommandBar
On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0

Application.OnKey "%{F11}", "dummy"

For Each oCB In Application.CommandBars
oCB.Enabled = False
Next oCB

mFormulaBar = Application.DisplayFormulaBar
Application.DisplayFormulaBar = False

RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
Application.OnTime RunWhen, "SaveAndClose", , True
End Sub

Followed by a module of -


Public RunWhen As Double
Public Const NUM_MINUTES = 5

Public Sub SaveAndClose()
ThisWorkbook.Close savechanges:=True
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
Application.OnTime RunWhen, "SaveAndClose", , True
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)

On Error Resume Next
Application.OnTime RunWhen, "SaveAndClose", , False
On Error GoTo 0
RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
Application.OnTime RunWhen, "SaveAndClose", , True

End Sub

 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      27th Jul 2009
haven't asked this already?

anyway
if this single line is by itself in the code page for ThisWorkbook, then
remove it

Application.OnTime RunWhen, "SaveAndClose", , False

code must be enclosed in a SUB or Function structure


change this
Private mFormulaBar
to
Public mFormulaBar

you need to tell us what the errors are.
At the top of each Module, type
OPTION EXPLICIT
this will not just force you to explicitly declare variables, its a great
way to prevent typos. Also, before you run code, use the menu Debug/Compile
VBAProject item - this will highlight obvious errors.
You need a sub named "dummy" in a standard module in order for this line to
compile:
Application.OnKey "%{F11}", "dummy"



"LiAD" <(E-Mail Removed)> wrote in message
news:B691A8D1-1777-45D9-92AD-(E-Mail Removed)...
> Hi,
>
> I am trying to use this code to hide the formula bars, menus etc and save
> and close a file after a certain time has passed, but i can't get it to
> run.
> Unfortunately I have reached the limit of what i know to try to fix the
> problem and get it to run. It errors on this line (line is in two places
> and
> both error).
>
> ----Application.OnTime RunWhen, "SaveAndClose", , False ------
>
> Any ideas how I can fix this?
> Thanks
> LiAD
>
> Entered as a workbook code
>
> Application.OnTime RunWhen, "SaveAndClose", , False
>
> Private mFormulaBar
>
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> Dim oCB As CommandBar
> On Error Resume Next
> Application.OnTime RunWhen, "SaveAndClose", , False
> On Error GoTo 0
> For Each oCB In Application.CommandBars
> oCB.Enabled = True
> Next oCB
>
> Application.DisplayFormulaBar = mFormulaBar
>
> Application.Quit
> End Sub
>
> Private Sub Workbook_Open()
> Dim oCB As CommandBar
> On Error Resume Next
> Application.OnTime RunWhen, "SaveAndClose", , False
> On Error GoTo 0
>
> Application.OnKey "%{F11}", "dummy"
>
> For Each oCB In Application.CommandBars
> oCB.Enabled = False
> Next oCB
>
> mFormulaBar = Application.DisplayFormulaBar
> Application.DisplayFormulaBar = False
>
> RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
> Application.OnTime RunWhen, "SaveAndClose", , True
> End Sub
>
> Followed by a module of -
>
>
> Public RunWhen As Double
> Public Const NUM_MINUTES = 5
>
> Public Sub SaveAndClose()
> ThisWorkbook.Close savechanges:=True
> End Sub
>
> Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
> Range)
> On Error Resume Next
> Application.OnTime RunWhen, "SaveAndClose", , False
> On Error GoTo 0
> RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
> Application.OnTime RunWhen, "SaveAndClose", , True
> End Sub
>
> Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
> ByVal Target As Range)
>
> On Error Resume Next
> Application.OnTime RunWhen, "SaveAndClose", , False
> On Error GoTo 0
> RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
> Application.OnTime RunWhen, "SaveAndClose", , True
>
> End Sub
>

 
Reply With Quote
 
LiAD
Guest
Posts: n/a
 
      27th Jul 2009
Cheers.

Works now just be removing the two lines and changing priv-public.

Yeah I had already asked, twice actually, but didnt make any progress.

Thanks a lot for your help


"Patrick Molloy" wrote:

> haven't asked this already?
>
> anyway
> if this single line is by itself in the code page for ThisWorkbook, then
> remove it
>
> Application.OnTime RunWhen, "SaveAndClose", , False
>
> code must be enclosed in a SUB or Function structure
>
>
> change this
> Private mFormulaBar
> to
> Public mFormulaBar
>
> you need to tell us what the errors are.
> At the top of each Module, type
> OPTION EXPLICIT
> this will not just force you to explicitly declare variables, its a great
> way to prevent typos. Also, before you run code, use the menu Debug/Compile
> VBAProject item - this will highlight obvious errors.
> You need a sub named "dummy" in a standard module in order for this line to
> compile:
> Application.OnKey "%{F11}", "dummy"
>
>
>
> "LiAD" <(E-Mail Removed)> wrote in message
> news:B691A8D1-1777-45D9-92AD-(E-Mail Removed)...
> > Hi,
> >
> > I am trying to use this code to hide the formula bars, menus etc and save
> > and close a file after a certain time has passed, but i can't get it to
> > run.
> > Unfortunately I have reached the limit of what i know to try to fix the
> > problem and get it to run. It errors on this line (line is in two places
> > and
> > both error).
> >
> > ----Application.OnTime RunWhen, "SaveAndClose", , False ------
> >
> > Any ideas how I can fix this?
> > Thanks
> > LiAD
> >
> > Entered as a workbook code
> >
> > Application.OnTime RunWhen, "SaveAndClose", , False
> >
> > Private mFormulaBar
> >
> > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > Dim oCB As CommandBar
> > On Error Resume Next
> > Application.OnTime RunWhen, "SaveAndClose", , False
> > On Error GoTo 0
> > For Each oCB In Application.CommandBars
> > oCB.Enabled = True
> > Next oCB
> >
> > Application.DisplayFormulaBar = mFormulaBar
> >
> > Application.Quit
> > End Sub
> >
> > Private Sub Workbook_Open()
> > Dim oCB As CommandBar
> > On Error Resume Next
> > Application.OnTime RunWhen, "SaveAndClose", , False
> > On Error GoTo 0
> >
> > Application.OnKey "%{F11}", "dummy"
> >
> > For Each oCB In Application.CommandBars
> > oCB.Enabled = False
> > Next oCB
> >
> > mFormulaBar = Application.DisplayFormulaBar
> > Application.DisplayFormulaBar = False
> >
> > RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
> > Application.OnTime RunWhen, "SaveAndClose", , True
> > End Sub
> >
> > Followed by a module of -
> >
> >
> > Public RunWhen As Double
> > Public Const NUM_MINUTES = 5
> >
> > Public Sub SaveAndClose()
> > ThisWorkbook.Close savechanges:=True
> > End Sub
> >
> > Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
> > Range)
> > On Error Resume Next
> > Application.OnTime RunWhen, "SaveAndClose", , False
> > On Error GoTo 0
> > RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
> > Application.OnTime RunWhen, "SaveAndClose", , True
> > End Sub
> >
> > Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
> > ByVal Target As Range)
> >
> > On Error Resume Next
> > Application.OnTime RunWhen, "SaveAndClose", , False
> > On Error GoTo 0
> > RunWhen = Now + TimeSerial(0, NUM_MINUTES, 0)
> > Application.OnTime RunWhen, "SaveAndClose", , True
> >
> > End Sub
> >

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access 2007 Disable Close and Close All on Tabbed Documents MumHeb Windows Vista 0 6th May 2010 05:36 PM
error in running workbook.close() func. after close excel from win Kayıhan Microsoft C# .NET 0 29th Mar 2009 12:49 AM
Clear Checkbox field on close of form or close of report =?Utf-8?B?QnJvb2s=?= Microsoft Access Form Coding 2 14th Jan 2006 09:31 PM
Excel shoud not close all active books when clicking close button =?Utf-8?B?dGVjaG5vbWlrZQ==?= Microsoft Excel Misc 0 10th Jun 2005 05:35 PM
Close all programs / Shut Down windows does not auto close outlook =?Utf-8?B?TUtlcw==?= Microsoft Word Document Management 2 22nd Aug 2004 11:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:31 PM.