Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default QueryTable.add naming problem (web query)

I have a procedure that loops through a list of hyperlinks on one worksheet
(wsSource) and calls an ImportWebData routine. The ImportWebData procedure
uses QueryTable.Add to grab the data, place it in a 2nd worksheet (wsTarget)
and name the range holding the import data as "ImportData" (using .Name).
Following the query, the mother routine calls "ProcessImportData" and passes
wsTarget and .range("ImportData")

After ProcessImportData, the mother procedure deletes the "ImportData" name
to re-use it on the next query.

Therein lies the problem. Each iteration of ImportWebData names the range
holding the imported data as "ImportData_1", "ImportData_2", etc. (even
though the name "ImportData" no longer exists.)

Here is my question followed by the sample code: How can I force the web
query to always name the imported data range as "ImportData" (without the
appended numbers)?
Sub GetAllWebData()
Dim wsT As Worksheet
Dim wsS As Worksheet
Dim hLink As Hyperlink
Dim sWebAddr As String
Const ImportRangeName As String = "ImportData"
Const iTableNumber As Integer = 9

Set wsT = Worksheets("TargetSheet")
Set wsS = Worksheets("SourceSheet")

For Each hLink In wsS.Hyperlinks
sWebAddr = hLink.Address
ImportWebData wsS, wsT, sWebAddr, iTableNumber, ImportRangeName
ProcessImportData wsT
Range(ImportRangeName).Delete
Next hLink
End Sub

Sub ImportWebData(wsSource As Worksheet, wsTarget As Worksheet, _
sWebAddr As String, iTableNumber As Integer, _
ImportRangeName As String)
Dim qTab As QueryTable

Set qTab = wsTarget.QueryTables.Add(Connection:="URL;" & sWebAddr, _
Destination:=wsTarget.Range("A1"))
With qTab
.Name = ImportRangeName
.FieldNames = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "11,12,13"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Application.qTab.Refresh BackgroundQuery:=False
End Sub

Sub ProcessImportData(ws As Worksheet)
' statements to evaluate, manipulate and make decisions based upon
' imported data located in ws.range(ImportRangeName)
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default QueryTable.add naming problem (web query)


A brief look suggests this could be simpler. Don't need hyperlinks, just the
url

Sub getdata()'UNtested
For Each murl In Range("whatever")
MsgBox murl
With ActiveSheet.QueryTables.Add(Connection:="URL;" & murl, _
Destination:=ActiveSheet.Range("A1"))
.Name = ImportRangeName
.SaveData = True
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "11,12,13"
.Refresh BackgroundQuery:=False
End With

'copy the data desired to somewhere and get the next

Next murl

End Sub
--
Don Guillett
SalesAid Software

"PeacefulAnd4getful" wrote in message
...
I have a procedure that loops through a list of hyperlinks on one worksheet
(wsSource) and calls an ImportWebData routine. The ImportWebData procedure
uses QueryTable.Add to grab the data, place it in a 2nd worksheet
(wsTarget) and name the range holding the import data as "ImportData"
(using .Name). Following the query, the mother routine calls
"ProcessImportData" and passes wsTarget and .range("ImportData")

After ProcessImportData, the mother procedure deletes the "ImportData"
name to re-use it on the next query.

Therein lies the problem. Each iteration of ImportWebData names the range
holding the imported data as "ImportData_1", "ImportData_2", etc. (even
though the name "ImportData" no longer exists.)

Here is my question followed by the sample code: How can I force the web
query to always name the imported data range as "ImportData" (without the
appended numbers)?
Sub GetAllWebData()
Dim wsT As Worksheet
Dim wsS As Worksheet
Dim hLink As Hyperlink
Dim sWebAddr As String
Const ImportRangeName As String = "ImportData"
Const iTableNumber As Integer = 9

Set wsT = Worksheets("TargetSheet")
Set wsS = Worksheets("SourceSheet")

For Each hLink In wsS.Hyperlinks
sWebAddr = hLink.Address
ImportWebData wsS, wsT, sWebAddr, iTableNumber, ImportRangeName
ProcessImportData wsT
Range(ImportRangeName).Delete
Next hLink
End Sub

Sub ImportWebData(wsSource As Worksheet, wsTarget As Worksheet, _
sWebAddr As String, iTableNumber As Integer, _
ImportRangeName As String)
Dim qTab As QueryTable

Set qTab = wsTarget.QueryTables.Add(Connection:="URL;" & sWebAddr, _
Destination:=wsTarget.Range("A1"))
With qTab
.Name = ImportRangeName
.FieldNames = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "11,12,13"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Application.qTab.Refresh BackgroundQuery:=False
End Sub

Sub ProcessImportData(ws As Worksheet)
' statements to evaluate, manipulate and make decisions based upon
' imported data located in ws.range(ImportRangeName)
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default I got your solution, 3 years later though

Just add this line when you want to delete the range name. For some reason, Excel remembers the old names used and just starts counting. And if you don't name it, Excel will name it for you. So really no point to even naming the querytables.add each time. Luckily, it loads the most recent data into Item 1 object.

Names(ActiveSheet.QueryTables.Item(1).Name).Delete

Hope this helps if you haven't figure out a solution yet. Wish I could figure out how to stop it from keeping track of each name it uses or reset it each time.

On Monday, May 14, 2007 2:22 PM PeacefulAnd4getful wrote:


I have a procedure that loops through a list of hyperlinks on one worksheet
(wsSource) and calls an ImportWebData routine. The ImportWebData procedure
uses QueryTable.Add to grab the data, place it in a 2nd worksheet (wsTarget)
and name the range holding the import data as "ImportData" (using .Name).
Following the query, the mother routine calls "ProcessImportData" and passes
wsTarget and .range("ImportData")

After ProcessImportData, the mother procedure deletes the "ImportData" name
to re-use it on the next query.

Therein lies the problem. Each iteration of ImportWebData names the range
holding the imported data as "ImportData_1", "ImportData_2", etc. (even
though the name "ImportData" no longer exists.)

Here is my question followed by the sample code: How can I force the web
query to always name the imported data range as "ImportData" (without the
appended numbers)?
Sub GetAllWebData()
Dim wsT As Worksheet
Dim wsS As Worksheet
Dim hLink As Hyperlink
Dim sWebAddr As String
Const ImportRangeName As String = "ImportData"
Const iTableNumber As Integer = 9

Set wsT = Worksheets("TargetSheet")
Set wsS = Worksheets("SourceSheet")

For Each hLink In wsS.Hyperlinks
sWebAddr = hLink.Address
ImportWebData wsS, wsT, sWebAddr, iTableNumber, ImportRangeName
ProcessImportData wsT
Range(ImportRangeName).Delete
Next hLink
End Sub

Sub ImportWebData(wsSource As Worksheet, wsTarget As Worksheet, _
sWebAddr As String, iTableNumber As Integer, _
ImportRangeName As String)
Dim qTab As QueryTable

Set qTab = wsTarget.QueryTables.Add(Connection:="URL;" & sWebAddr, _
Destination:=wsTarget.Range("A1"))
With qTab
.Name = ImportRangeName
.FieldNames = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "11,12,13"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Application.qTab.Refresh BackgroundQuery:=False
End Sub

Sub ProcessImportData(ws As Worksheet)
' statements to evaluate, manipulate and make decisions based upon
' imported data located in ws.range(ImportRangeName)
End Sub



On Monday, May 14, 2007 4:03 PM Don Guillett wrote:


A brief look suggests this could be simpler. Don't need hyperlinks, just the
url

Sub getdata()'UNtested
For Each murl In Range("whatever")
MsgBox murl
With ActiveSheet.QueryTables.Add(Connection:="URL;" & murl, _
Destination:=ActiveSheet.Range("A1"))
.Name = ImportRangeName
.SaveData = True
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "11,12,13"
.Refresh BackgroundQuery:=False
End With

'copy the data desired to somewhere and get the next

Next murl

End Sub
--
Don Guillett
SalesAid Software

"PeacefulAnd4getful" wrote in message
...



Submitted via EggHeadCafe - Software Developer Portal of Choice
Make The WebClient Class follow redirects and get Target Url
http://www.eggheadcafe.com/tutorials...arget-url.aspx
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
Problem:Query Cell contain Formula from QueryTable is always get old value Resant Excel Programming 1 March 3rd 06 07:28 AM
Excel Web Query using a QueryTable via HTTPS?? Bing Excel Programming 2 April 2nd 05 03:51 PM
Selection.QueryTable problem JenC Excel Programming 2 January 7th 05 05:32 AM
Querytable naming cells Ray Excel Programming 6 September 22nd 04 04:31 PM
MS QUERY w/out querytable No Name Excel Programming 1 October 24th 03 03:55 PM


All times are GMT +1. The time now is 08:52 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"