Çözüldü İnternet Üzerinden UserForm a bilgi aktarma Hakkında

veysikulte1

Altın Üye
Katılım
23 Ekim 2015
Mesajlar
83
Excel Vers. ve Dili
2016
Altın Üyelik Bitiş Tarihi
19-04-2027
Merhabalar internet üzerinden userform a Label e dolar ve euro görüntüleme kodu aşağıdaki gibi yaptım kod çalışıyor ancak internet olmadığında hata veriyor. bu kodu nasıl internet olmadığında label caption boş görünsün internet varsa güncellensin. Bu konuda yardımcı olursanız sevinirim. şimdiden teşekkürler.

Kod:
Sub kurgetir()

Dim ie As New InternetExplorer
ie.Visible = False

ie.navigate "https://www.bloomberght.com/doviz"

Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE

Dim doc As HTMLDocument
Set doc = ie.document

UserForm1.Label49.Caption = doc.getElementsByClassName("LastPrice")(1).innerHTML
UserForm1.Label50.Caption = doc.getElementsByClassName("LastPrice")(2).innerHTML

ie.Quit


End Sub
 

EmrExcel16

Destek Ekibi
Destek Ekibi
Katılım
1 Kasım 2012
Mesajlar
1,524
Excel Vers. ve Dili
Office 365 Türkçe
Merhaba Aşağıdaki kodları dener misiniz?
Kod:
Declare Function InternetGetConnectedStateEx Lib "wininet.dll" _
       (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, _
        ByVal dwNameLen As Integer, ByVal dwReserved As Long) As Long
Dim strConn As String * 255

Sub kurgetir()

Dim ie As New InternetExplorer

If Test_Internet_Connection = True Then

    ie.Visible = False
  
    ie.navigate "https://www.bloomberght.com/doviz"
  
    Do
    DoEvents
    Loop Until ie.readyState = READYSTATE_COMPLETE
  
    Dim doc As HTMLDocument
    Set doc = ie.document
  
    UserForm1.Label49.Caption = doc.getElementsByClassName("LastPrice")(1).innerHTML
    UserForm1.Label50.Caption = doc.getElementsByClassName("LastPrice")(2).innerHTML
  
    ie.Quit
Else
    UserForm1.Label49.Caption = ""
    UserForm1.Label50.Caption = ""
End if
End Sub

Function Test_Internet_Connection() As Boolean
    Dim RetVal As Long
    RetVal = InternetGetConnectedStateEx(RetVal, strConn, 254, 0)
    If RetVal = 1 Then
        Test_Internet_Connection = True
    Else
        Test_Internet_Connection = False
    End If
End Function
 
Son düzenleme:

veysikulte1

Altın Üye
Katılım
23 Ekim 2015
Mesajlar
83
Excel Vers. ve Dili
2016
Altın Üyelik Bitiş Tarihi
19-04-2027
Merhaba Aşağıdaki kodları dener misiniz?
Kod:
Declare Function InternetGetConnectedStateEx Lib "wininet.dll" _
       (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, _
        ByVal dwNameLen As Integer, ByVal dwReserved As Long) As Long
Dim strConn As String * 255

Sub kurgetir()

Dim ie As New InternetExplorer

If Test_Internet_Connection = True Then

    ie.Visible = False
   
    ie.navigate "https://www.bloomberght.com/doviz"
   
    Do
    DoEvents
    Loop Until ie.readyState = READYSTATE_COMPLETE
   
    Dim doc As HTMLDocument
    Set doc = ie.document
   
    UserForm1.Label49.Caption = doc.getElementsByClassName("LastPrice")(1).innerHTML
    UserForm1.Label50.Caption = doc.getElementsByClassName("LastPrice")(2).innerHTML
   
    ie.Quit
Else
    UserForm1.Label49.Caption = ""
    UserForm1.Label50.Caption = ""
End Sub

Function Test_Internet_Connection() As Boolean
    Dim RetVal As Long
    RetVal = InternetGetConnectedStateEx(RetVal, strConn, 254, 0)
    If RetVal = 1 Then
        Test_Internet_Connection = True
    Else
        Test_Internet_Connection = False
    End If
End Function

Hocam kodu ekleyince artık userform hiç açılmadı ekteki hatayı alıyor kapanıyor. dosyayı kopyalamıştım :)
 

Ekli dosyalar

Kekoli

Altın Üye
Katılım
4 Aralık 2017
Mesajlar
134
Excel Vers. ve Dili
Excell 2016
Altın Üyelik Bitiş Tarihi
11-02-2025
yaptığınız çalışmayı paylaşmanızda bir sakınca yoksa paylaşabilir misiniz?
öğrenmek amaçlı incelemek istiyorum.
 

veysikulte1

Altın Üye
Katılım
23 Ekim 2015
Mesajlar
83
Excel Vers. ve Dili
2016
Altın Üyelik Bitiş Tarihi
19-04-2027
Dosya boyutu yüksek olduğu için eklenmiyor
 

EmrExcel16

Destek Ekibi
Destek Ekibi
Katılım
1 Kasım 2012
Mesajlar
1,524
Excel Vers. ve Dili
Office 365 Türkçe
Merhaba 1. kodu Userform içindeki butona 2. kodu boş bir modüle kopyalayıp dener misiniz.
Kod:
Private Sub CommandButton1_Click()

Dim ie As New InternetExplorer

If Test_Internet_Connection = True Then

    ie.Visible = False
    
    ie.navigate "https://www.bloomberght.com/doviz"
    
    Do
    DoEvents
    Loop Until ie.readyState = READYSTATE_COMPLETE
    
    Dim doc As HTMLDocument
    Set doc = ie.document
    
    UserForm1.Label49.Caption = doc.getElementsByClassName("LastPrice")(1).innerHTML
    UserForm1.Label50.Caption = doc.getElementsByClassName("LastPrice")(2).innerHTML
    
    ie.Quit
Else
    UserForm1.Label49.Caption = ""
    UserForm1.Label50.Caption = ""
End If

End Sub
Kod:
Declare Function InternetGetConnectedStateEx Lib "wininet.dll" _
       (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, _
        ByVal dwNameLen As Integer, ByVal dwReserved As Long) As Long
Dim strConn As String * 255

Function Test_Internet_Connection() As Boolean
    Dim RetVal As Long
    RetVal = InternetGetConnectedStateEx(RetVal, strConn, 254, 0)
    If RetVal = 1 Then
        Test_Internet_Connection = True
    Else
        Test_Internet_Connection = False
    End If
End Function
 

veysikulte1

Altın Üye
Katılım
23 Ekim 2015
Mesajlar
83
Excel Vers. ve Dili
2016
Altın Üyelik Bitiş Tarihi
19-04-2027
Merhaba 1. kodu Userform içindeki butona 2. kodu boş bir modüle kopyalayıp dener misiniz.
Kod:
Private Sub CommandButton1_Click()

Dim ie As New InternetExplorer

If Test_Internet_Connection = True Then

    ie.Visible = False
   
    ie.navigate "https://www.bloomberght.com/doviz"
   
    Do
    DoEvents
    Loop Until ie.readyState = READYSTATE_COMPLETE
   
    Dim doc As HTMLDocument
    Set doc = ie.document
   
    UserForm1.Label49.Caption = doc.getElementsByClassName("LastPrice")(1).innerHTML
    UserForm1.Label50.Caption = doc.getElementsByClassName("LastPrice")(2).innerHTML
   
    ie.Quit
Else
    UserForm1.Label49.Caption = ""
    UserForm1.Label50.Caption = ""
End If

End Sub
Kod:
Declare Function InternetGetConnectedStateEx Lib "wininet.dll" _
       (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, _
        ByVal dwNameLen As Integer, ByVal dwReserved As Long) As Long
Dim strConn As String * 255

Function Test_Internet_Connection() As Boolean
    Dim RetVal As Long
    RetVal = InternetGetConnectedStateEx(RetVal, strConn, 254, 0)
    If RetVal = 1 Then
        Test_Internet_Connection = True
    Else
        Test_Internet_Connection = False
    End If
End Function
Hocam bu şekilde çalışıyor ancak butona bağlı olmasını istemiyorum userform açılınca internet bağlantısı yoksa boş görünsün internet bağlantısı varsa görünsün
 

EmrExcel16

Destek Ekibi
Destek Ekibi
Katılım
1 Kasım 2012
Mesajlar
1,524
Excel Vers. ve Dili
Office 365 Türkçe
Ozaman 1. kodu aşağıdaki gibi değiştiriniz.
Kod:
Private Sub UserForm_Initialize()
Dim ie As New InternetExplorer

If Test_Internet_Connection = True Then

    ie.Visible = False
    
    ie.navigate "https://www.bloomberght.com/doviz"
    
    Do
    DoEvents
    Loop Until ie.readyState = READYSTATE_COMPLETE
    
    Dim doc As HTMLDocument
    Set doc = ie.document
    
    UserForm1.Label49.Caption = doc.getElementsByClassName("LastPrice")(1).innerHTML
    UserForm1.Label50.Caption = doc.getElementsByClassName("LastPrice")(2).innerHTML
    ie.Quit
Else
    UserForm1.Label49.Caption = ""
    UserForm1.Label50.Caption = ""
    MsgBox "Internet Yok"
End If
End Sub
 

veysikulte1

Altın Üye
Katılım
23 Ekim 2015
Mesajlar
83
Excel Vers. ve Dili
2016
Altın Üyelik Bitiş Tarihi
19-04-2027
Ozaman 1. kodu aşağıdaki gibi değiştiriniz.
Kod:
Private Sub UserForm_Initialize()
Dim ie As New InternetExplorer

If Test_Internet_Connection = True Then

    ie.Visible = False
   
    ie.navigate "https://www.bloomberght.com/doviz"
   
    Do
    DoEvents
    Loop Until ie.readyState = READYSTATE_COMPLETE
   
    Dim doc As HTMLDocument
    Set doc = ie.document
   
    UserForm1.Label49.Caption = doc.getElementsByClassName("LastPrice")(1).innerHTML
    UserForm1.Label50.Caption = doc.getElementsByClassName("LastPrice")(2).innerHTML
    ie.Quit
Else
    UserForm1.Label49.Caption = ""
    UserForm1.Label50.Caption = ""
    MsgBox "Internet Yok"
End If
End Sub

Çok Teşekkür ederim tam istediğim gibi oldu (y)(y)(y)(y)
 
Üst