We help IT Professionals succeed at work.
Get Started

Web Query macro from excel to VB.net

MichMat
MichMat asked
on
963 Views
Last Modified: 2012-06-21
Hallo,

I have a VBA macro in a workbook that I use to get some data from webpage, I use late binding to opperate the workbooks macros from VB.net program and exceute the macros like that. I would now like to place the macro into the VB.net code, however I am getting this error on the first line of the code

Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

I am including the two codes bellow the first one is the VB.Net code that is throwing the error
the second one is the Original VBA code Im trying to convert

Thank you

Michal

'My converted VBA code
objSheetsM.Activate()
'the following line gets the error #################################
        With objSheetsM.QueryTables.Add(Connection:= _
            "URL;" & objSheetsH.Range("A1").Text, Destination:= _
            objSheetsM.Range("$A$1").Value)
'##########################################################
            .Name = "mtgraces"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = 1
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .WebSelectionType = 1
            .WebFormatting = 3
            .WebPreFormattedTextToColumns = True
            .WebConsecutiveDelimitersAsOne = True
            .WebSingleBlockTextImport = False
            .WebDisableDateRecognition = False
            .WebDisableRedirections = False
            .Refresh(BackgroundQuery:=False)
        End With
 
 
'The VBA ORIGINAL code that I am trying to conver
 
ThisWorkbook.Sheets("Meetings").Activate
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;" & ThisWorkbook.Sheets("Address").Range("A1").Value, Destination:= _
        Range("$A$1"))
        .Name = "mtgraces"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With

Open in new window

Comment
Watch Question
Developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE