I do something similar, try the below, you might need to adapt it a bit to meet your needs, but if you've got any questions please ask.
I've set the url to one you will be able to download (thanks Jerry
)
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal _
szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Sub SaveTaskfromWeb()
Const startHour As String = "09:00"
Const url As String = "https://sites.google.com/a/madrocketscientist.com/jerrybeaucaires-excelassistant/files/3D-VLOOKUP%26HYPERLINK.xls"
Dim startTime As String
Dim fPath As String
Dim cValue As String
Dim wb As Workbook
Dim fname As Variant
On Error GoTo handler
fPath = DownloadFilefrURL(url)
Set wb = Workbooks.Open(fPath)
With wb
cValue = .Sheets("Sheet1").Range("A5").Text
.Close False
End With
fname = Split(url, "/")
fname = fname(UBound(fname))
startTime = Format(Now() + 1, "dd/MM/yyyy " & startHour)
If CreateAppointment(startTime, fname & " - " & cValue) Then
MsgBox "Outlook appointment created", vbInformation
Else
MsgBox "Something went wrong, the appointment was not created.", vbCritical
End If
Exit Sub
handler:
If Err.Number = 76 Then
MsgBox "The file was not downloaded, please check the url.", vbCritical
Else
MsgBox Err.Description, vbCritical
End If
End Sub
Public Function DownloadFilefrURL(url As String) As String
Dim strSavePath As String
Dim ext As String
Dim buf, ret As Long
buf = Split(url, ".")
ext = buf(UBound(buf))
strSavePath = ThisWorkbook.Path & "\" & "DownloadedFile." & ext
ret = URLDownloadToFile(0, url, strSavePath, 0, 0)
If ret = 0 Then
DownloadFilefrURL = strSavePath
Else
Err.Raise 76
End If
End Function
Public Function CreateAppointment(startTime As String, Subject As String) As Boolean
Dim oApp As Object
Dim oNameSpace As Object
Dim oItem As Object
Dim iLastRow As Long
Dim irow As Long
On Error Resume Next
Set oApp = GetObject("outlook.application")
If Err <> 0 Then
Set oApp = CreateObject("Outlook.Application")
End If
Err.Clear
On Error GoTo handler
Set oNameSpace = oApp.GetNamespace("MAPI")
Set oItem = oApp.CreateItem(1)
With oItem
.Subject = Subject
.Start = startTime
.Display '.Save 'change to this if you'd rather save
CreateAppointment = True
End With
Exit Function
handler:
CreateAppointment = False
End Function
Bookmarks