thst
Gebruiker
- Lid geworden
- 10 apr 2001
- Berichten
- 655
Hallo Allemaal,
Ik heb een VBA code die in mijn sheet uitstekend werkt, alleen er zit geen melding in als de postcode niet bestaat, graag zou ik een melding willen zien in Cells(21, 13) zoiets van Foutive postcode, als de postcodes wel bestaan zet de code in die cel het aantal kilometers.
Angela
Private Sub CommandButton1_Click()
Application.Calculate
strvanpc = Worksheets(6).Cells(16, 16)
strvanplaats = Worksheets(6).Cells(14, 1)
strnaar1pc = Worksheets(6).Cells(17, 16)
strnaar1plaats = Worksheets(6).Cells(15, 1)
strnaar2pc = Worksheets(6).Cells(18, 16)
strnaar2plaats = Worksheets(6).Cells(16, 1)
strnaar3pc = Worksheets(6).Cells(19, 16)
strnaar3plaats = Worksheets(6).Cells(17, 1)
strnaar4pc = Worksheets(6).Cells(20, 16)
strnaar4plaats = Worksheets(6).Cells(18, 1)
Map = Worksheets(6).Cells(15, 11)
strLink = "http://maps.google.nl/maps?f=d&source=s_d&saddr=" & strvanpc & "+" & strvanplaats & "&daddr=" & strnaar1pc & "+" & strnaar1plaats & "+to:" & strnaar2pc & "+" & strnaar2plaats & "+to:" & strnaar3pc & "+" & strnaar3plaats & "+to:" & strnaar4pc & "+" & strnaar4plaats & "&hl=nl&geocode=&mra=ls&sll=51.238135,5.69546&sspn=0.121661,0.356712&ie=UTF8&z=12"
''ActiveWorkbook.FollowHyperlink (strLink), , True
Dim objexplorer As Object
Set objexplorer = CreateObject("InternetExplorer.Application")
objexplorer.navigate (strLink)
Do While objexplorer.Busy
DoEvents
Loop
objexplorer.Visible = Map
''http://www.associatedcontent.com/article/1506423/internet_explorerapplication_for_vba_pg3.html?cat=55
strSearchedIn = objexplorer.document.body.innerhtml
strSearchedFor1 = "Routebeschrijving naar"
intPosition1 = InStr(1, strSearchedIn, strSearchedFor1)
strSearchedFor2 = "<DIV><B>"
strSearchedFor3 = "</B>"
intPosition2 = InStr(intPosition1, strSearchedIn, strSearchedFor2) + Len(strSearchedFor2)
intPosition3 = InStr(intPosition2, strSearchedIn, strSearchedFor3)
strDistance = Replace(Mid(strSearchedIn, intPosition2, intPosition3 - intPosition2), " ", "")
strSearchedFor4 = "<B>"
strSearchedFor5 = "</B>"
intPosition4 = InStr(intPosition3, strSearchedIn, strSearchedFor4) + Len(strSearchedFor4)
intPosition5 = InStr(intPosition4, strSearchedIn, strSearchedFor5)
strTime = Mid(strSearchedIn, intPosition4, intPosition5 - intPosition4)
Worksheets(6).Cells(21, 13) = Replace(strDistance, "km", "")
Worksheets(6).Cells(30, 13) = strTime
Application.Calculate
End Sub
Ik heb een VBA code die in mijn sheet uitstekend werkt, alleen er zit geen melding in als de postcode niet bestaat, graag zou ik een melding willen zien in Cells(21, 13) zoiets van Foutive postcode, als de postcodes wel bestaan zet de code in die cel het aantal kilometers.
Angela
Private Sub CommandButton1_Click()
Application.Calculate
strvanpc = Worksheets(6).Cells(16, 16)
strvanplaats = Worksheets(6).Cells(14, 1)
strnaar1pc = Worksheets(6).Cells(17, 16)
strnaar1plaats = Worksheets(6).Cells(15, 1)
strnaar2pc = Worksheets(6).Cells(18, 16)
strnaar2plaats = Worksheets(6).Cells(16, 1)
strnaar3pc = Worksheets(6).Cells(19, 16)
strnaar3plaats = Worksheets(6).Cells(17, 1)
strnaar4pc = Worksheets(6).Cells(20, 16)
strnaar4plaats = Worksheets(6).Cells(18, 1)
Map = Worksheets(6).Cells(15, 11)
strLink = "http://maps.google.nl/maps?f=d&source=s_d&saddr=" & strvanpc & "+" & strvanplaats & "&daddr=" & strnaar1pc & "+" & strnaar1plaats & "+to:" & strnaar2pc & "+" & strnaar2plaats & "+to:" & strnaar3pc & "+" & strnaar3plaats & "+to:" & strnaar4pc & "+" & strnaar4plaats & "&hl=nl&geocode=&mra=ls&sll=51.238135,5.69546&sspn=0.121661,0.356712&ie=UTF8&z=12"
''ActiveWorkbook.FollowHyperlink (strLink), , True
Dim objexplorer As Object
Set objexplorer = CreateObject("InternetExplorer.Application")
objexplorer.navigate (strLink)
Do While objexplorer.Busy
DoEvents
Loop
objexplorer.Visible = Map
''http://www.associatedcontent.com/article/1506423/internet_explorerapplication_for_vba_pg3.html?cat=55
strSearchedIn = objexplorer.document.body.innerhtml
strSearchedFor1 = "Routebeschrijving naar"
intPosition1 = InStr(1, strSearchedIn, strSearchedFor1)
strSearchedFor2 = "<DIV><B>"
strSearchedFor3 = "</B>"
intPosition2 = InStr(intPosition1, strSearchedIn, strSearchedFor2) + Len(strSearchedFor2)
intPosition3 = InStr(intPosition2, strSearchedIn, strSearchedFor3)
strDistance = Replace(Mid(strSearchedIn, intPosition2, intPosition3 - intPosition2), " ", "")
strSearchedFor4 = "<B>"
strSearchedFor5 = "</B>"
intPosition4 = InStr(intPosition3, strSearchedIn, strSearchedFor4) + Len(strSearchedFor4)
intPosition5 = InStr(intPosition4, strSearchedIn, strSearchedFor5)
strTime = Mid(strSearchedIn, intPosition4, intPosition5 - intPosition4)
Worksheets(6).Cells(21, 13) = Replace(strDistance, "km", "")
Worksheets(6).Cells(30, 13) = strTime
Application.Calculate
End Sub