VBA: Run-time error '438': Object doesn't support this property or method

SteveOranjin

Board Regular
Joined
Dec 18, 2017
Messages
170
Hello,

I can't figure out what is going on with this. The Error I get is,

"Run-time error '438': Object Doesn't Support This Property or method." and then it highlights the following.

".ListObject.DisplayName"

I have highlighted it red in the code.

two values to enter into the input box is ,"BRZ", or "ASB"

Code:
Sub Macro3()
'Defining Variables
Dim myValue As Variant
Dim Link As Variant


'Creating a link
Link = "http://cf3.myplumbingshowroom.com/scheduledScripts/brandDataAPI.cfm?brandCode="


'creating a the variable to be passed into the link
myValue = InputBox("Enter your brand code here")


'completing our link
Link = "http://cf3.myplumbingshowroom.com/scheduledScripts/brandDataAPI.cfm?brandCode=" & myValue
'checking if it exists
MsgBox Link


'if the query already exists, we're going to delete it. Otherwise, we're going to ignore that function.


On Error Resume Next
ActiveWorkbook.Queries("brandDataAPI").Delete
On Error GoTo 0




    Application.CutCopyMode = False
    ActiveWorkbook.Queries.Add Name:="brandDataAPI", Formula:= _
        "let" & Chr(13) & "" & Chr(10) & "    Source = Csv.Document(Web.Contents(" & Link & "),[Delimiter="","", Columns=11, Encoding=1252, QuoteStyle=QuoteStyle.None])," & Chr(13) & "" & Chr(10) & "    #""Promoted Headers"" = Table.PromoteHeaders(Source, [PromoteAllScalars=true])," & Chr(13) & "" & Chr(10) & "    #""Changed Type"" = Table.TransformColumnTypes(#""Promoted Header" & _
        "s"",{{""BrandName"", type text}, {"" BrandCode"", type text}, {"" BrandID"", Int64.Type}, {"" datalastUpdate"", type date}, {"" numproducts"", Int64.Type}, {""priceMethod"", type text}, {""URL"", type text}, {""showPrice"", Int64.Type}, {""MAP_YN"", Int64.Type}, {""MAP"", type text}, {""msrpNotes"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Changed Type"""
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
        "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""brandDataAPI"";Extended Properties=""""" _
        , Destination:=Range("$A$1")).QueryTable
        .CommandType = xlCmdSql
        .CommandText = Array("SELECT * FROM [brandDataAPI]")
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = False
        .Refresh BackgroundQuery:=True
[COLOR=#ff0000]        .ListObject.DisplayName[/COLOR]
    End With
End Sub
 
Last edited:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
By the way, I'm trying to import a table here. I'm importing it from the internet.

I want to do this so I can have my VBA grab and populate fields directly from the source.

Steve
 
Upvote 0
It looks like the .ListObject is redundant to the ListObjects.Add, so I would try removing .ListObject and just make that line
Code:
.DisplayName
 
Upvote 0
If that does not work, you will probably have to do that as a separate bit of code. It does not show as a property of the ListObjects.Add method.
 
Upvote 0
If that does not work, you will probably have to do that as a separate bit of code. It does not show as a property of the ListObjects.Add method.

Can you walk me through how to do that? I don't know how to do that.

What that guy recommended to me did not work.

Steve
 
Upvote 0
If that does not work, you will probably have to do that as a separate bit of code. It does not show as a property of the ListObjects.Add method.

It shows as a property if you include the query table bit (shorthand below):

Code:
ListObjects.Add.QueryTable.ListObject.DisplayName

What are you trying to do with the display name string?

Are you trying to assign it somewhere, or change it? That property is just a string, not an action.
 
Upvote 0
Hello Steve,

The property DisplayName applies to specific ListObject in the ListObjects collection. You have created a List Object that contains a Query Table. To return or change the name of List Object, you must reference the parent object of the Query Table. In this case, the parent object of the Query Table is the List Object.

Code:
Sub Macro3()


    'Defining Variables
    Dim myValue As Variant
    Dim Link    As Variant
    Dim oQuery  As Object


        'Creating a link
        Link = "http://cf3.myplumbingshowroom.com/scheduledScripts/brandDataAPI.cfm?brandCode="


        'creating a the variable to be passed into the link
        myValue = InputBox("Enter your brand code here")


        'completing our link
        Link = "http://cf3.myplumbingshowroom.com/scheduledScripts/brandDataAPI.cfm?brandCode=" & myValue
        'checking if it exists
        MsgBox Link


        'if the query already exists, we're going to delete it. Otherwise, we're going to ignore that function.


        On Error Resume Next
            ActiveWorkbook.Queries("brandDataAPI").Delete
        On Error GoTo 0


        Application.CutCopyMode = False
        ActiveWorkbook.Queries.Add Name:="brandDataAPI", Formula:= _
            "let" & Chr(13) & "" & Chr(10) & "    Source = Csv.Document(Web.Contents(" & Link & "),[Delimiter="","", Columns=11, Encoding=1252, QuoteStyle=QuoteStyle.None])," & Chr(13) & "" & Chr(10) & "    #""Promoted Headers"" = Table.PromoteHeaders(Source, [PromoteAllScalars=true])," & Chr(13) & "" & Chr(10) & "    #""Changed Type"" = Table.TransformColumnTypes(#""Promoted Header" & _
            "s"",{{""BrandName"", type text}, {"" BrandCode"", type text}, {"" BrandID"", Int64.Type}, {"" datalastUpdate"", type date}, {"" numproducts"", Int64.Type}, {""priceMethod"", type text}, {""URL"", type text}, {""showPrice"", Int64.Type}, {""MAP_YN"", Int64.Type}, {""MAP"", type text}, {""msrpNotes"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Changed Type"""
    
        'Create a ListObjet that holds a Query Table.
        Set oQuery = ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
            "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""brandDataAPI"";Extended Properties=""""" _
            , Destination:=Range("$A$1")).QueryTable


        'Execute the query and save the results in the List Object just created.
        With oQuery
            .CommandType = xlCmdSql
            .CommandText = Array("SELECT * FROM [brandDataAPI]")
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .PreserveColumnInfo = False
            .Refresh BackgroundQuery:=True
            .Parent.DisplayName = "Brand Data"  'This is the name of the newly added ListObject.
        End With
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,665
Members
449,091
Latest member
peppernaut

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