Get dollar to peso exchange rate from a website for any given date

namariegaudi

New Member
Joined
Oct 14, 2016
Messages
14
Hi, this coding is totally new to me
I have a website our company usually goes to get the official exchange rate of dollar /peso (there are 2 values, FIX and Interbancario) I would need the later. Is there a way to build a macro that given a date in Excel goes to the website listed here:

and provide the exchange rate and put it in a cell within the Excel file that contains the macro?

Regards
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi, other option

VBA Code:
Sub TableExample()
'by Jonny'
Dim IE As Object
Dim doc As Object
Dim strURL As String

strURL = "https://www.banxico.org.mx/tipcamb/main.do?page=tip&idioma=sp"

Set IE = CreateObject("InternetExplorer.Application")
With IE
     '.Visible = True

    .navigate strURL
    Do Until .readyState = 4: DoEvents: Loop
        Do While .Busy: DoEvents: Loop
            Set doc = IE.document
            GetAllTables doc

            .Quit
        End With
End Sub

Sub GetAllTables(doc As Object)

     ' get all the tables from a webpage document, doc, and put them in a new worksheet

    Dim ws As Worksheet
    Dim rng As Range
    Dim tbl As Object
    Dim rw As Object
    Dim cl As Object
    Dim tabno As Long
    Dim nextrow As Long
    Dim I As Long

    Set ws = ActiveSheet

    For Each tbl In doc.getElementsByTagName("TABLE")
        tabno = tabno + 1
        nextrow = nextrow + 1
        Set rng = ws.Range("B" & nextrow)
        rng.Offset(, -1) = "Table " & tabno
        For Each rw In tbl.Rows
            For Each cl In rw.Cells
                rng.Value = cl.outerText
                Set rng = rng.Offset(, 1)
                I = I + 1
            Next cl
            nextrow = nextrow + 1
            Set rng = rng.Offset(1, -I)
            I = 0
        Next rw
    Next tbl

    ws.Cells.ClearFormats

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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