• DİKKAT

    DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
    Altın Üyelik Hakkında Bilgi

Web'deki dosyayı Excell'de otomatik açma

  • Konbuyu başlatan Konbuyu başlatan Kekoli
  • Başlangıç tarihi Başlangıç tarihi
Katılım
4 Aralık 2017
Mesajlar
134
Excel Vers. ve Dili
Excell 2016
Merhaba,

otomatik olarak her ay upload edilen bir excel dosyası var ve linki hiç değişmiyor.
bir tane makro yazmak istiyorum ve dosyayı her açtığımda linkteki dosyayı çekip içindeki tabloyu benim excelimde açsın, ben de sonrasında onu istediğim şekle sokacak makro uyarlamaları yapacağım.

linkteki dosyayı kendi dosyama girince çekip içinde açmasını nasıl sağlayabilirim? linke tıklayınca bilgisayara direk .xlsx download oluyor.
 

Kod:
Option Explicit

Sub ImportHistoricalDataSheet()

    Const SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS = 13056
    Const adSaveCreateOverWrite = 2

    Dim aBody, sPath

    ' Download Historical Data xls file via XHR
    With CreateObject("MSXML2.XMLHTTP")
    'With CreateObject("MSXML2.ServerXMLHTTP")
        '.SetOption 2, SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
        .Open "GET", "http://www.housepriceindex.ca/Excel2.aspx?langue=EN&mail=abc%40abc.com"
        .Send
        ' Get binary response content
        aBody = .responseBody
        ' Retrieve filename from headers and concatenate full path
        sPath = ThisWorkbook.Path & "\" & Replace(Split(Split(.GetAllResponseHeaders, "filename=", 2)(1), vbCrLf, 2)(0), "/", "-")
    End With
    ' Save binary content to the xls file
    With CreateObject("ADODB.Stream")
        .Type = 1
        .Open
        .Write aBody
        .SaveToFile sPath, adSaveCreateOverWrite
        .Close
    End With
    ' Open saved workbook
    With Workbooks.Open(sPath, , True)
        ' Get 1st worksheet values to array
        aBody = .Worksheets(1).UsedRange.Value
        .Saved = True
        .Close
    End With
    ' Delete saved workbook file
    CreateObject("Scripting.FileSystemObject").DeleteFile sPath, True
    ' Insert array to target worksheet
    ThisWorkbook.Sheets("Sheet1").Cells(1, 1).Resize(UBound(aBody, 1), UBound(aBody, 2)).Value = aBody

End Sub
 
Geri
Üst