Please edit this macro for me...thanks everyone!

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
:bow:The below code works very well but it is design for both ANALOG CLOCK & DIGITAL CLOCK: ANALOG CLOCK is prepared with the help of MS PPT. I just want this macro to be edited for DIGITAL CLOCK only.

Please help...any help will be appriciated:


Sub Updateclok()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
' Updates the clock that's visible<o:p></o:p>
Dim Clock As Chart<o:p></o:p>
Set Clock = ThisWorkbook.Sheets("Sheet1").ChartObjects("ClockChart").Chart<o:p></o:p>
<o:p></o:p>
If Clock.Parent.Visible Then<o:p></o:p>
' ANALOG CLOCK<o:p></o:p>
Const PI As Double = 3.14159265358979<o:p></o:p>
Dim CurrentSeries As Series<o:p></o:p>
Dim s As Series<o:p></o:p>
Dim x(1 To 2) As Variant<o:p></o:p>
Dim v(1 To 2) As Variant<o:p></o:p>
<o:p></o:p>
' Hour hand<o:p></o:p>
Set CurrentSeries = Clock.SeriesCollection("HourHand")<o:p></o:p>
x(1) = 0<o:p></o:p>
x(2) = 0.5 * Sin((Hour(Time) + (Minute(Time) / 60)) * (2 * PI / 12))<o:p></o:p>
v(1) = 0<o:p></o:p>
v(2) = 0.5 * Cos((Hour(Time) + (Minute(Time) / 60)) * (2 * PI / 12))<o:p></o:p>
CurrentSeries.XValues = x<o:p></o:p>
CurrentSeries.Values = v<o:p></o:p>
<o:p></o:p>
' Minute hand<o:p></o:p>
Set CurrentSeries = Clock.SeriesCollection("MinuteHand")<o:p></o:p>
x(1) = 0<o:p></o:p>
x(2) = 0.8 * Sin((Minute(Time) + (Second(Time) / 60)) * (2 * PI / 60))<o:p></o:p>
v(1) = 0<o:p></o:p>
v(2) = 0.8 * Cos((Minute(Time) + (Second(Time) / 60)) * (2 * PI / 60))<o:p></o:p>
CurrentSeries.XValues = x<o:p></o:p>
CurrentSeries.Values = v<o:p></o:p>
<o:p></o:p>
' Second hand<o:p></o:p>
Set CurrentSeries = Clock.SeriesCollection("SecondHand")<o:p></o:p>
x(1) = 0<o:p></o:p>
x(2) = 0.85 * Sin(Second(Time) * (2 * PI / 60))<o:p></o:p>
v(1) = 0<o:p></o:p>
v(2) = 0.85 * Cos(Second(Time) * (2 * PI / 60))<o:p></o:p>
CurrentSeries.XValues = x<o:p></o:p>
CurrentSeries.Values = v<o:p></o:p>
Else<o:p></o:p>
' DIGITAL CLOCK<o:p></o:p>
ThisWorkbook.Sheets("Sheet1").Range("DigitalClock").Value = CDbl(Time)<o:p></o:p>
End If<o:p></o:p>
<o:p></o:p>
' Set up the next event one second from now<o:p></o:p>
NextTick = Now + TimeValue("00:00:01")<o:p></o:p>
Application.OnTime NextTick, "Updateclok"<o:p></o:p>
<o:p></o:p>
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
...ANALOG CLOCK is prepared with the help of MS PPT...

...I just want this macro to be edited for DIGITAL CLOCK only...

Given that the "digital clock" appears to be naught be a simple cell this particular code would not be applicatable to PowerPoint. Furthermore at least up through PowerPoint 2007, the PowerPoint application's object model does not support the OnTime method.

If I have misunderstood and this will indeed be running in Excel then all you need to do is delete the lines pertaining to the analog clock, i.e. you end up with:
Rich (BB code):
Sub Updateclok()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
' DIGITAL CLOCK<o:p></o:p>
ThisWorkbook.Sheets("Sheet1").Range("DigitalClock").Value = CDbl(Time)<o:p></o:p>

' Set up the next event one second from now<o:p></o:p>
NextTick = Now + TimeValue("00:00:01")<o:p></o:p>
Application.OnTime NextTick, "Updateclok"
 
End Sub


Also, please use code tags when posting code.
 
Last edited:
Upvote 0
:bow:The below code works very well but it is design for both ANALOG CLOCK & DIGITAL CLOCK: ANALOG CLOCK is prepared with the help of MS PPT. I just want this macro to be edited for DIGITAL CLOCK only.

Please help...any help will be appriciated:


Sub Updateclok()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
' Updates the clock that's visible<o:p></o:p>
Dim Clock As Chart<o:p></o:p>
Set Clock = ThisWorkbook.Sheets("Sheet1").ChartObjects("ClockChart").Chart<o:p></o:p>
<o:p></o:p>
If Clock.Parent.Visible Then<o:p></o:p>
' ANALOG CLOCK<o:p></o:p>
Const PI As Double = 3.14159265358979<o:p></o:p>
Dim CurrentSeries As Series<o:p></o:p>
Dim s As Series<o:p></o:p>
Dim x(1 To 2) As Variant<o:p></o:p>
Dim v(1 To 2) As Variant<o:p></o:p>
<o:p></o:p>
' Hour hand<o:p></o:p>
Set CurrentSeries = Clock.SeriesCollection("HourHand")<o:p></o:p>
x(1) = 0<o:p></o:p>
x(2) = 0.5 * Sin((Hour(Time) + (Minute(Time) / 60)) * (2 * PI / 12))<o:p></o:p>
v(1) = 0<o:p></o:p>
v(2) = 0.5 * Cos((Hour(Time) + (Minute(Time) / 60)) * (2 * PI / 12))<o:p></o:p>
CurrentSeries.XValues = x<o:p></o:p>
CurrentSeries.Values = v<o:p></o:p>
<o:p></o:p>
' Minute hand<o:p></o:p>
Set CurrentSeries = Clock.SeriesCollection("MinuteHand")<o:p></o:p>
x(1) = 0<o:p></o:p>
x(2) = 0.8 * Sin((Minute(Time) + (Second(Time) / 60)) * (2 * PI / 60))<o:p></o:p>
v(1) = 0<o:p></o:p>
v(2) = 0.8 * Cos((Minute(Time) + (Second(Time) / 60)) * (2 * PI / 60))<o:p></o:p>
CurrentSeries.XValues = x<o:p></o:p>
CurrentSeries.Values = v<o:p></o:p>
<o:p></o:p>
' Second hand<o:p></o:p>
Set CurrentSeries = Clock.SeriesCollection("SecondHand")<o:p></o:p>
x(1) = 0<o:p></o:p>
x(2) = 0.85 * Sin(Second(Time) * (2 * PI / 60))<o:p></o:p>
v(1) = 0<o:p></o:p>
v(2) = 0.85 * Cos(Second(Time) * (2 * PI / 60))<o:p></o:p>
CurrentSeries.XValues = x<o:p></o:p>
CurrentSeries.Values = v<o:p></o:p>
Else<o:p></o:p>
' DIGITAL CLOCK<o:p></o:p>
ThisWorkbook.Sheets("Sheet1").Range("DigitalClock").Value = CDbl(Time)<o:p></o:p>
End If<o:p></o:p>
<o:p></o:p>
' Set up the next event one second from now<o:p></o:p>
NextTick = Now + TimeValue("00:00:01")<o:p></o:p>
Application.OnTime NextTick, "Updateclok"<o:p></o:p>
<o:p></o:p>
Please help!!!
 
Upvote 0
Now - does my above response help at all? I have provided the same level of detail you are providing. If you want more helpful responses then you might consider providing more information - like the error message being returned and the line being highlighted. You would also want to confirm that you are trying to run this in Excel and not PowerPoint.
 
Upvote 0
Not to belabor the point, but I tested the code I posted and it works just fine. Perhaps you didn't see part 2 of my response?
 
Upvote 0
Greg Truby,

The error message is as given below:

Error: Run time error '1004':

Application-defined or object-defined error


When i click on debug

Sub Updateclok()
' DIGITAL CLOCK
ThisWorkbook.Sheets("Sheet1").Range("DigitalClock").Value = CDbl(Time)
' Set up the next event one second from now
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "Updateclok"

End Sub
 
Upvote 0
Again, I'm assuming you are indeed running this in Excel and not trying to run this in PowerPoint...

Does your workbook have a sheet named Sheet1?

Does Sheet1 have a named range with the name DigitalClock?

Edit - also, it's not a bad idea to put code in the workbook's BeforeClose event handler that will kill the OnTime process. Otherwise you may find Excel reopening the workbook every second.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top