Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EXCEL VBA - Connecting to SQL more than required!!!

Status
Not open for further replies.

Josh01

Programmer
Jan 9, 2002
23
GB
I am trying to run the following query with VBA when the worksheet in Excel is opened:

Private Sub Workbook_Open()
Dim mine As Worksheet

Dim runsheet As Worksheet
Dim sheetcount As Integer

sheetcount = 2

Do Until sheetcount = ThisWorkbook.Sheets.Count + 1
Set runsheet = Sheets(sheetcount)
runsheet.Visible = xlSheetHidden
sheetcount = sheetcount + 1
Loop

Run ("Josh1")

End Sub

Where "Josh1" is:

Sub Josh1()
'
' Josh1 Macro
' Macro recorded 17/01/02 by M700NTBUILD
'
'Refreshes data in pivot table

Sheets("Data").Visible = True
Sheets("Data").Select
ActiveSheet.PivotTables("PivotTable2").RefreshTable
Sheets("Data").Visible = False

End Sub

It all works fine except that the pivottable refresh runs twice when the worksheet is opened. Anyone have any ideas as to how to make it only run the once?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top