?
Solved

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

Posted on 2003-02-20
6
Medium Priority
?
217 Views
Last Modified: 2012-10-05
could someone please tell me how to write the VBA code to automatically update a pivot table every 30 secs?  much apprecitated.

Jason
0
Comment
Question by:jason1234
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 50

Expert Comment

by:Dave Brett
ID: 7991439
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
 
LVL 50

Accepted Solution

by:
Dave Brett earned 200 total points
ID: 7991501
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
 

Author Comment

by:jason1234
ID: 8007567
Thanks v. much..... works a treat!

again - thanks.
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 8012995
No problem Jason :)

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

Cheers

Dave

0
 
LVL 15

Expert Comment

by:dbase118
ID: 9582622
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

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question