close

I am using a work sheet that links by DDE to a machine PLC.
It is updating once a second. I have a time of day clock built into the sheed.
How can I run a worksheet quot;Printquot; macro based on time of day from a selected
cell?

If the time to run the macro is in cell A1, use

Application.OnTime Range(quot;A1quot;).Value,quot;Printquot;

where Print is the name of the macro to run.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
quot;Brucequot; gt; wrote in message
news
gt;I am using a work sheet that links by DDE to a machine PLC.
gt; It is updating once a second. I have a time of day clock built
gt; into the sheed.
gt; How can I run a worksheet quot;Printquot; macro based on time of day
gt; from a selected
gt; cell?
Check out Excel's Application.OnTime method. I have never used it personally
but it supposedly can display alarms, print things, do whatever, whenever
certain time is reached. You may want to use the TimeValue function along
with the method for determining the time you want the thing to print.

Hope this helps.

Bill Horton

quot;Brucequot; wrote:

gt; I am using a work sheet that links by DDE to a machine PLC.
gt; It is updating once a second. I have a time of day clock built into the sheed.
gt; How can I run a worksheet quot;Printquot; macro based on time of day from a selected
gt; cell?

Something like the following (but changed to print stuff)

Sub SetAlarm()
Application.OnTime 0.625, quot;DisplayAlarmquot;
End Sub

Sub DisplayAlarm()
Beep
MsgBox quot;Wake up. It's time for your afternoon break!quot;
End Sub

Taken from Excel VBA Programming For Dummies

Hope this helps.

Bill Horton

quot;Brucequot; wrote:

gt; I am using a work sheet that links by DDE to a machine PLC.
gt; It is updating once a second. I have a time of day clock built into the sheed.
gt; How can I run a worksheet quot;Printquot; macro based on time of day from a selected
gt; cell?

gt; Application.OnTime 0.625, quot;DisplayAlarmquot;

While the above code will work just fine, it would be better to
use TimeSerial or TimeValue to get the appropriate time. Unless
you know how Excel treats time, the 0.625 is meaningless. Good
programming practice would be

Application.OnTime TimeSerial(15,0,0), quot;DisplayAlarmquot;
or
Application.OnTime TimeValue(quot;15:00:00quot;),quot;DisplayAlarmquot;--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

quot;William Hortonquot; gt; wrote
in message
news
gt; Something like the following (but changed to print stuff)
gt;
gt; Sub SetAlarm()
gt; Application.OnTime 0.625, quot;DisplayAlarmquot;
gt; End Sub
gt;
gt; Sub DisplayAlarm()
gt; Beep
gt; MsgBox quot;Wake up. It's time for your afternoon break!quot;
gt; End Sub
gt;
gt; Taken from Excel VBA Programming For Dummies
gt;
gt; Hope this helps.
gt;
gt; Bill Horton
gt;
gt; quot;Brucequot; wrote:
gt;
gt;gt; I am using a work sheet that links by DDE to a machine PLC.
gt;gt; It is updating once a second. I have a time of day clock built
gt;gt; into the sheed.
gt;gt; How can I run a worksheet quot;Printquot; macro based on time of day
gt;gt; from a selected
gt;gt; cell?
Chip
We are using excel 2002. Not sure it includes Application On Time.
How can I tell
Thanks

quot;Chip Pearsonquot; wrote:

gt; If the time to run the macro is in cell A1, use
gt;
gt; Application.OnTime Range(quot;A1quot;).Value,quot;Printquot;
gt;
gt; where Print is the name of the macro to run.
gt;
gt; --
gt; Cordially,
gt; Chip Pearson
gt; Microsoft MVP - Excel
gt; Pearson Software Consulting, LLC
gt; www.cpearson.com
gt;
gt;
gt;
gt; quot;Brucequot; gt; wrote in message
gt; news
gt; gt;I am using a work sheet that links by DDE to a machine PLC.
gt; gt; It is updating once a second. I have a time of day clock built
gt; gt; into the sheed.
gt; gt; How can I run a worksheet quot;Printquot; macro based on time of day
gt; gt; from a selected
gt; gt; cell?
gt;
gt;
gt;

Bruce,

The OnTime method exists in Excel 2002.--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
quot;Brucequot; gt; wrote in message
news
gt; Chip
gt; We are using excel 2002. Not sure it includes Application On
gt; Time.
gt; How can I tell
gt; Thanks
gt;
gt; quot;Chip Pearsonquot; wrote:
gt;
gt;gt; If the time to run the macro is in cell A1, use
gt;gt;
gt;gt; Application.OnTime Range(quot;A1quot;).Value,quot;Printquot;
gt;gt;
gt;gt; where Print is the name of the macro to run.
gt;gt;
gt;gt; --
gt;gt; Cordially,
gt;gt; Chip Pearson
gt;gt; Microsoft MVP - Excel
gt;gt; Pearson Software Consulting, LLC
gt;gt; www.cpearson.com
gt;gt;
gt;gt;
gt;gt;
gt;gt; quot;Brucequot; gt; wrote in message
gt;gt; news
gt;gt; gt;I am using a work sheet that links by DDE to a machine PLC.
gt;gt; gt; It is updating once a second. I have a time of day clock
gt;gt; gt; built
gt;gt; gt; into the sheed.
gt;gt; gt; How can I run a worksheet quot;Printquot; macro based on time of day
gt;gt; gt; from a selected
gt;gt; gt; cell?
gt;gt;
gt;gt;
gt;gt;
Chip
I am new to code
Here is what I have

Sub SetAlarm()
Application.OnTime Range(quot;C5quot;).Value(quot;8:19:00quot;), quot;autoprintquot;
End Sub

The autoprint macro works from a button in the worksheet but not in the code
Do I need to do something in the worksheet to turn it on?
Thanks

quot;Chip Pearsonquot; wrote:

gt; gt; Application.OnTime 0.625, quot;DisplayAlarmquot;
gt;
gt; While the above code will work just fine, it would be better to
gt; use TimeSerial or TimeValue to get the appropriate time. Unless
gt; you know how Excel treats time, the 0.625 is meaningless. Good
gt; programming practice would be
gt;
gt; Application.OnTime TimeSerial(15,0,0), quot;DisplayAlarmquot;
gt; or
gt; Application.OnTime TimeValue(quot;15:00:00quot;),quot;DisplayAlarmquot;
gt;
gt;
gt; --
gt; Cordially,
gt; Chip Pearson
gt; Microsoft MVP - Excel
gt; Pearson Software Consulting, LLC
gt; www.cpearson.com
gt;
gt;
gt;
gt;
gt; quot;William Hortonquot; gt; wrote
gt; in message
gt; news
gt; gt; Something like the following (but changed to print stuff)
gt; gt;
gt; gt; Sub SetAlarm()
gt; gt; Application.OnTime 0.625, quot;DisplayAlarmquot;
gt; gt; End Sub
gt; gt;
gt; gt; Sub DisplayAlarm()
gt; gt; Beep
gt; gt; MsgBox quot;Wake up. It's time for your afternoon break!quot;
gt; gt; End Sub
gt; gt;
gt; gt; Taken from Excel VBA Programming For Dummies
gt; gt;
gt; gt; Hope this helps.
gt; gt;
gt; gt; Bill Horton
gt; gt;
gt; gt; quot;Brucequot; wrote:
gt; gt;
gt; gt;gt; I am using a work sheet that links by DDE to a machine PLC.
gt; gt;gt; It is updating once a second. I have a time of day clock built
gt; gt;gt; into the sheed.
gt; gt;gt; How can I run a worksheet quot;Printquot; macro based on time of day
gt; gt;gt; from a selected
gt; gt;gt; cell?
gt;
gt;
gt;

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()