Macro for Auto Refreshing a pivot table every 30 secs for example

could someone please tell me how to write the VBA code to automatically update a pivot table every 30 secs?  much apprecitated.

Jason
jason1234Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DaveCommented:
You could try

Cheers
Dave

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRunWhat = "Update_PivotTable"

Sub auto_open()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
    schedule:=True
End Sub

Sub Update_PivotTable()
For Each Pt In ActiveWorkbook.PivotCaches
Pt.Refresh
Next
auto_open
End Sub
0
DaveCommented:
Whoops, needed a close routine to turn the OnTime routine off. Otherwise the file reopens


Public RunWhen As Double
Public Const cRunIntervalSeconds = 3
Public Const cRunWhat = "Update_PivotTable"

Sub auto_open()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
    schedule:=True
End Sub

Sub Update_PivotTable()
For Each Pt In ThisWorkbook.PivotCaches
Pt.Refresh
Next
auto_open
End Sub

Sub auto_close()
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
    schedule:=False
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jason1234Author Commented:
Thanks v. much..... works a treat!

again - thanks.
0
DaveCommented:
No problem Jason :)

Can you please close it off by accepting my second comment as an answer

Cheers

Dave

0
dbase118Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ \ Answered by brettdj
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

dbase118
EE Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.