Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Macro query refresh fails

I recorded a macro that does a refresh on a SQL query cell. I can record it
OK (refresh works during record), but running it produces a "1004" error on
the line that is attempting to refresh the query. Anyone know why this
happens and how to fix it?

Sheets("Sheet1").Visible = True
Range("A2").Select
Selection.QueryTable.Refresh BackgroundQuery:=False (1004 error)
Range("A2").Select
Selection.Copy
Sheets("Data").Select
Range("A15").Select
ActiveSheet.Paste
Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.Visible = False
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Macro query refresh fails

Querytables is a property of the Sheet object. So, if the query is in
Sheet1, try:

Worksheets("Sheet1").QueryTables(1).Refresh BackgroundQuery:=False


--
Hope that helps.

Vergel Adriano


"rick_mc" wrote:

I recorded a macro that does a refresh on a SQL query cell. I can record it
OK (refresh works during record), but running it produces a "1004" error on
the line that is attempting to refresh the query. Anyone know why this
happens and how to fix it?

Sheets("Sheet1").Visible = True
Range("A2").Select
Selection.QueryTable.Refresh BackgroundQuery:=False (1004 error)
Range("A2").Select
Selection.Copy
Sheets("Data").Select
Range("A15").Select
ActiveSheet.Paste
Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.Visible = False

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
external data automatic refresh through macro/query Texas Tonie[_2_] Excel Discussion (Misc queries) 0 April 12th 07 07:52 PM
Refresh BackgroundQuery fails JMMach[_2_] Excel Programming 3 June 12th 05 03:10 PM
Timing of automatic query refresh and macro pivot table refresh dutty Excel Programming 2 December 1st 04 07:19 PM
Macro to execute on WEB Query Refresh Donnie Stone Excel Programming 1 September 30th 03 02:16 PM
Web Query Refresh - Automatically Run Macro Donnie Stone Excel Programming 1 September 19th 03 05:49 AM


All times are GMT +1. The time now is 12:25 PM.

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

About Us

"It's about Microsoft Excel"