URL works w/Power Query but not Macro or Manualy

jane2geo

New Member
Joined
Jul 12, 2018
Messages
2
I've been hacking around VBA since Office 95
Most of my code is that old and has worked flawlessly up to 2003
I recall my code working in 2007 [OS was XP] as well but lost that in a fire.
So years back I got 2010 and every football preseason I work
countless hours trying to migrate my code only to retreat and
continue using ver.2003

This URL works as expected with the Power Query feature, selecting Table 1.

http://g.sportsdatabase.com/nfl/que...ite=home+and+season=2018&submit=++S+D+Q+L+!++

However, in VBA code or manually building a web query it does not work.
A 1004 error in VBA , at .Refresh BackgroundQuery:=False ,,,, or unable
to open / can not download when using the GUI method.
Additionally, when the IE pops up I must cancel out of several script errors in both 2003 and 2010, but still 2003 is successful and 2010 is not.
Code:
Sub Button1_Click()
  Dim f As Worksheet
     
    Set f = Sheets("Sheet1")
    With f.Range("A10:Y544").Clear
    End With

    Dim objWeb As QueryTable
    Dim sWebTable As String

    sWebTable = 4
  
    Set objWeb = Sheets("Sheet1").QueryTables.Add( _
    Connection:="URL;http://g.sportsdatabase.com/nfl/query?output=default&sdql=week%2C+date%2C+team%2C+o%3Ateam%2C+line+%40+week%3D1++and+site%3Dhome+and+season%3D2018&submit=++S+D+Q+L+%21++", _
    Destination:=Sheets("Sheet1").Range("A10"))
   
    With objWeb

                .FieldNames = False
                .RowNumbers = False
                .FillAdjacentFormulas = False
                .PreserveFormatting = True
                .RefreshOnFileOpen = False
                .BackgroundQuery = True
                .RefreshStyle = xlInsertDeleteCells
                .SavePassword = False
                .SaveData = True  'was true 20120627
                .AdjustColumnWidth = False
                .RefreshPeriod = 0
                .WebSelectionType = xlSpecifiedTables
                .WebFormatting = xlWebFormattingNone
                .WebTables = sWebTable
                .WebPreFormattedTextToColumns = True
                .WebConsecutiveDelimitersAsOne = True
                .WebSingleBlockTextImport = False
                .WebDisableDateRecognition = True 'try false
                .WebDisableRedirections = False
                .Refresh BackgroundQuery:=False  ' was false


        
    End With
    Set objWeb = Nothing

End Sub

My gut tells me this is a security issue and every year I google the same
sequrity options and regedits over and over to no avail. But then why does the
Power Query work just fine?

Thanks for reading

My setup
Win 7 Pro 64
Excel 2010 32bit
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Wow, this is a busy place.
Any help will be greatly appreciated.
<!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:DoNotRelyOnCSS/> <o:DoNotUseLongFilenames/> </o:OfficeDocumentSettings> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top