ActiveWorkbook.Queries.Add error

brkkrkmz112

New Member
Joined
Oct 24, 2016
Messages
43
Hello everyone,

While getting data from web , I am getting an error on the "ActiveWorkbook.Queries.Add Name:" line . The error is number 438 does not support object etc. Could anyone one help me on this.

Thanks in advance.


VBA Code:
Sub KapanisVeriCek()
    Dim tname As String
    tarih = Format(Date, "ddmmyyyy")
    zaman = Format(Time, "hhmmss")
    ActiveWorkbook.RefreshAll
    'On Error GoTo 10
    Sheets("Hisseler").Select
    Cells.Select
    'Selection.ClearContents
    Range("A1").Select
    tname = "Tablo" & tarih & zaman
    
    
    
        ActiveWorkbook.Queries.Add Name:=tname, Formula:= _
        "let" & Chr(13) & "" & Chr(10) & "    Source = Web.Page(Web.Contents(""https://www.isyatirim.com.tr/tr-tr/analiz/hisse/Sayfalar/Temel-Degerler-Ve-Oranlar.aspx#page-1""))," & Chr(13) & "" & Chr(10) & "    Data2 = Kaynak{2}[Data]," & Chr(13) & "" & Chr(10) & "    #""Değiştirilen Tür"" = Table.TransformColumnTypes(Data2,{{""Kod"", type text}, {""Hisse Adı"", type text}, {""Sektör"", type text}, {""Kapanış (TL)"", type number}, {""Piyasa Değeri (mn TL)" & _
        """, type number}, {""Piyasa Değeri (mn $)"", type number}, {""Halka Açıklık Oranı (%)"", type number}, {""Sermaye (mn TL)"", type number}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Değiştirilen Tür"""
    
    
    
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
        "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=" & tname & ";Extended Properties=""""" _
        , Destination:=Range("$A$1")).QueryTable
        .CommandType = xlCmdSql
        .CommandText = Array("SELECT * FROM [" & tname & "]")
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlOverwriteCells 'xlOverwriteCells   'xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .ListObject.DisplayName = tname
        .Refresh BackgroundQuery:=False
    End With
    ActiveSheet.ListObjects(tname).TableStyle = "TableStyleMedium6"
    'Range("& tname &[[#Headers],[Kod]]").Select
    Application.CommandBars("Queries and Connections").Visible = False
    Call portfoy
    Range("O1").Value = Format(Date, "dd.mm.yyyy")
    Exit Sub
10 MsgBox " Muhtemel olmayan bir hata ile karşılaşıldı. Programdan çıkılacaktır...", vbCritical, " Kritik bilgi "
ActiveWorkbook.Close savechanges:=False
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Replace ActiveWorkbook.Queries.Add by
ActiveSheet.Queries.Add
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,962
Latest member
Fenes

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