Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default running VB code

I have a template which refreshes the data (from an
external data source) on opening the template. I then
want to remove a row and do a subtotal over the data by
running some VBA code. When I step through the code, it
works fine, but at runtime, on opening the template I get
an error.
I have tried putting the data refresh into the code, but
it doesn't help.
I am new to excel programming, but this is what I've done
so far...

Private Sub Workbook_Open()

'Worksheets(1).Activate
Set currentcell = Worksheets(1).Range("A5")
Worksheets(1).Range("A5").QueryTable.Refresh

Set currentcell = Worksheets(1).Range("A5")
currentcell.EntireRow.Delete

'ActiveCell.EntireRow.Delete

'Set currentCell = Worksheets(1).Range("A5")
Range("A5").Select

Selection.Subtotal groupBy:=1, Function:=xlSum, _
totalList:=Array(7)

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default running VB code

The usual problem is that you are doing a background query and the code
completes before the query does. This should fix it:

Private Sub Workbook_Open()

'Worksheets(1).Activate
Set currentcell = Worksheets(1).Range("A5")
Worksheets(1).Range("A5").QueryTable.Refresh _
Backgroundquery:=False

Set currentcell = Worksheets(1).Range("A5")
currentcell.EntireRow.Delete

'ActiveCell.EntireRow.Delete

'Set currentCell = Worksheets(1).Range("A5")
Range("A5").Select

Selection.Subtotal groupBy:=1, Function:=xlSum, _
totalList:=Array(7)

End Sub

--
Regards,
Tom Ogilvy


"Cath" wrote in message
...
I have a template which refreshes the data (from an
external data source) on opening the template. I then
want to remove a row and do a subtotal over the data by
running some VBA code. When I step through the code, it
works fine, but at runtime, on opening the template I get
an error.
I have tried putting the data refresh into the code, but
it doesn't help.
I am new to excel programming, but this is what I've done
so far...

Private Sub Workbook_Open()

'Worksheets(1).Activate
Set currentcell = Worksheets(1).Range("A5")
Worksheets(1).Range("A5").QueryTable.Refresh

Set currentcell = Worksheets(1).Range("A5")
currentcell.EntireRow.Delete

'ActiveCell.EntireRow.Delete

'Set currentCell = Worksheets(1).Range("A5")
Range("A5").Select

Selection.Subtotal groupBy:=1, Function:=xlSum, _
totalList:=Array(7)

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running code on workdays chrisnsmith Excel Worksheet Functions 2 February 4th 09 06:58 PM
VB code for running a macro rcc Excel Discussion (Misc queries) 3 January 23rd 08 02:53 AM
Automatically running code Richard Excel Worksheet Functions 1 February 7th 06 09:35 PM
running code mark New Users to Excel 3 March 14th 05 09:14 AM
Running Code in an XLA from a Worksheet Chrissy[_4_] Excel Programming 6 October 11th 03 11:27 PM


All times are GMT +1. The time now is 02:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"