Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
AG AG is offline
external usenet poster
 
Posts: 54
Default Web Query Doesnt Load Unless I Open It 1st

I have queries saved in the file C:\Documents and Settings\Al\Application
Data\Microsoft\Queries\MStar.
Individually they all work fine.

However, when I open a workbook and use its VBA macro to run the queries no
data is found.

I find that if I then go to one of my stored queries, open it directly and
then go back to my workbook and re-run the macro everything works fine.

Am I missing something in my code?

VBA:
Sub Large()
'
' Copies MStar total returns for funds


Application.DisplayAlerts = False
On Error Resume Next
Sheets("Large").Select
Sheets.Add
ActiveSheet.Select
ActiveSheet. Name = "Sheet1"

IQYFile = "C:\Documents and Settings\Al\Application Data\Microsoft\" & _
"Queries\MStar\RGAEX.iqy"

With ActiveSheet.QueryTables.Add(Connection:= _
"FINDER;" & IQYFile, Destination:=Range("A1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SaveData = True
End With

Range("A3:E7").Select
Selection.Copy
Sheets("Large").Select
Columns("B:B").Select
Selection.Find(What:="RGEAX", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 10).Range("A1").Select
ActiveSheet.Paste
Sheets("Sheet1").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.Delete The code continues on for other
queries.

A sample of one of the queries would be:

WEB
1
http://quicktake.morningstar.com/Fun...&fdtab=returns

Selection=15
Formatting=None
PreFormattedTextToColumns=True
ConsecutiveDelimitersAsOne=True
SingleBlockTextImport=False
DisableDateRecognition=False
DisableRedirections=False

Thanks for any help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Web Query Doesnt Load Unless I Open It 1st

I don't use iqy anyomore. Try putting your url directly into the macro

Application.DisplayAlerts = False
On Error Resume Next

Sheets.Add
ActiveSheet. Name = "Sheet1"

'untested
With activesheet.QueryTables.Add(Connection:="URL;" _
& "http://quicktake.morningstar.com/Fun...&fdtab=returns", _
Destination:=activesheet.range("a1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = true
.Refresh BackgroundQuery:=False
.SaveData = True
End With

with Sheets("Large")
x=.Columns("B").Find(What:="RGEAX", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 10).Range("A1").address
Range("A3:E7").copy .range(x)
end with

UN tested
Your other queries could probably be in a loopextract desired datagoto the
next one using one macro and one data sheet.

--
Don Guillett
SalesAid Software

"AG" wrote in message
...
I have queries saved in the file C:\Documents and Settings\Al\Application
Data\Microsoft\Queries\MStar.
Individually they all work fine.

However, when I open a workbook and use its VBA macro to run the queries
no
data is found.

I find that if I then go to one of my stored queries, open it directly and
then go back to my workbook and re-run the macro everything works fine.

Am I missing something in my code?

VBA:
Sub Large()
'
' Copies MStar total returns for funds


Application.DisplayAlerts = False
On Error Resume Next
Sheets("Large").Select
Sheets.Add
ActiveSheet.Select
ActiveSheet. Name = "Sheet1"

IQYFile = "C:\Documents and Settings\Al\Application Data\Microsoft\" &
_
"Queries\MStar\RGAEX.iqy"

With ActiveSheet.QueryTables.Add(Connection:= _
"FINDER;" & IQYFile, Destination:=Range("A1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SaveData = True
End With

Range("A3:E7").Select
Selection.Copy
Sheets("Large").Select
Columns("B:B").Select
Selection.Find(What:="RGEAX", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 10).Range("A1").Select
ActiveSheet.Paste
Sheets("Sheet1").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.Delete The code continues on for other
queries.

A sample of one of the queries would be:

WEB
1
http://quicktake.morningstar.com/Fun...&fdtab=returns

Selection=15
Formatting=None
PreFormattedTextToColumns=True
ConsecutiveDelimitersAsOne=True
SingleBlockTextImport=False
DisableDateRecognition=False
DisableRedirections=False

Thanks for any help.


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
XLL loading fails unless load through File Open msdn_groupie Excel Programming 0 May 7th 07 06:56 PM
Load caption box on userform open ExcelMonkey Excel Worksheet Functions 1 April 3rd 07 11:02 PM
Problems During Load (XML file Open) bantar Excel Programming 0 July 6th 06 07:29 PM
How do I down load excel to open email attachment? confused Excel Discussion (Misc queries) 2 February 24th 06 05:40 AM
Macro to load on open Steve Chatham[_2_] Excel Programming 6 February 11th 04 07:20 PM


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

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"