Advertisement
Guest User

Kurs Aktualisierung

a guest
Feb 16th, 2015
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Public Function getData(ISIN As String, stockType As String, Optional returnValue As Integer)
  4. Dim wstemp As Worksheet
  5. Dim URL As String
  6.  
  7.   On Error GoTo errHandler
  8.  
  9.   Select Case LCase(stockType)
  10.     ' Anleihe
  11.    Case "bond"
  12.       URL = "https://wertpapiere.ing-diba.de/DE/Showpage.aspx?pageID=41&ISIN="
  13.     ' Aktie
  14.    Case "stock", "share"
  15.       URL = "https://wertpapiere.ing-diba.de/DE/Showpage.aspx?pageID=23&ISIN="
  16.     ' ETF
  17.    Case "etf"
  18.       URL = "https://wertpapiere.ing-diba.de/DE/Showpage.aspx?pageID=30&ISIN="
  19.     ' wtf
  20.    Case Else
  21.       getData = "ERROR - wrong stock type"
  22.       Exit Function
  23.   End Select
  24.  
  25.   Set wstemp = Worksheets("temp")
  26.  
  27.   wstemp.Range("A1:IV65535").ClearContents
  28.  
  29.   With wstemp.QueryTables.Add(Connection:="URL;" & URL & Trim(ISIN) & "", Destination:=wstemp.Range("A1"))
  30.       .FieldNames = True
  31.       .RowNumbers = False
  32.       .FillAdjacentFormulas = False
  33.       .PreserveFormatting = False
  34.       .RefreshOnFileOpen = False
  35.       .BackgroundQuery = True
  36.       .RefreshStyle = xlInsertDeleteCells
  37.       .SavePassword = False
  38.       .SaveData = True
  39.       .AdjustColumnWidth = True
  40.       .RefreshPeriod = 0
  41.       .WebSelectionType = xlAllTables
  42.       .WebFormatting = xlWebFormattingNone
  43.       .WebPreFormattedTextToColumns = True
  44.       .WebConsecutiveDelimitersAsOne = True
  45.       .WebSingleBlockTextImport = False
  46.       .WebDisableDateRecognition = False
  47.       .WebDisableRedirections = False
  48.       .Refresh BackgroundQuery:=False
  49.   End With
  50.   DoEvents
  51.  
  52.   ' error handling
  53.  If wstemp.Range("A1").Value = "" Or IsNumeric(wstemp.Range("A1").Value) = False Then
  54.     getData = "ERROR - return Value was zero"
  55.     Exit Function
  56.   Else
  57.     If returnValue <> 0 Then
  58.       getData = CDbl(wstemp.Range("B16").Value)
  59.     Else
  60.       getData = CDbl(wstemp.Range("A1").Value)
  61.     End If
  62.   End If
  63.  
  64.   wstemp.Range("A1:IV65535").ClearContents
  65.   wstemp.Range("A1:IV65535").QueryTable.Delete
  66.  
  67. Exit Function
  68.  
  69. errHandler:
  70.   getData = "ERROR"
  71.  
  72. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement