Mustangdave05
New Member
- Joined
- Apr 19, 2011
- Messages
- 3
I have been searching everwhere for an answer and have tried numerous examples of code found on the internet. Nothing seems to work. This is what I am trying to do...
I have a workbook that retrieves data from a file from a URL address upon opening. Actually, I am saving the URL file to a local drive and then updating my workbook with this data. The problem is that the job that updates the URL file sometimes fails. I want to notify the user of my workbook that the data has not been update recently. I am trying to use the built in document properties (Last Save Time) but I cannot get it to work except for the workbook that has the macros in it. Is there a way to find the last save time of a workbook (from a URL address) seperate from the workbook that has the marco? Below is my current code that errors out at: dp = Application.Workbooks("DockReportExport.xls").BuiltinDocumentProperties("Last Save Time") with and runtime error.
Thanks for your help in advance!!!!
Sub FTP()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
'Open file from URL addres to check last save time
Workbooks.Open Filename:="http://172.16.1.94/Files/Operations/Dock/LoadBuilder/DockReportExport.xls"
'Check if data on server has been updated in the last 15 minutes
Dim dp
dp = Application.Workbooks("DockReportExport.xls").BuiltinDocumentProperties("Last Save Time")
Dim cd
cd = Now() '- 0.0104 '0.0104 = 15 minutes
ActiveWorkbook.Close SaveChanges:=False
If dp < cd Then 'ask if user wants to continue or stop
Response1 = MsgBox("Data on server has not been update since " & dp & "." _
& vbCr & "Select YES to continue using data from server." & vbCr _
& "Select NO to stop.", 4, "Old data on server!", 0, 0)
If Response1 = vbNo Then
goto 10
End if
End if
'download file from URL and save to local drive
Dim ret As Long
ret = URLDownloadToFile(0, "http://172.16.1.94/Files/Operations/Dock/LoadBuilder/DockReportExport.xls", "c:\LoadBuilder\DockReportExport.xls", 0, 0)
'Open local file and copy date to my workbook
Workbooks.Open Filename:="c:\LoadBuilder\DockReportExport.xls"
Range("$A:$BB").Select
Selection.Copy
Windows("Truck Builder.xls").Activate
Sheet10.Visible = xlSheetVisible
Sheets("Dock Report").Select
Range("B1").Select
ActiveSheet.Paste
Workbooks("DockReportExport.xls").Worksheets("Transport - Merge Report").Activate
Application.CutCopyMode = False
ActiveWindow.Close SaveChanges:=False
Sheets("TRUCK BUILDING").Select
Sheet10.Visible = xlSheetVeryHidden
Application.DisplayAlerts = True
Application.ScreenUpdating = True
10 End sub
I have a workbook that retrieves data from a file from a URL address upon opening. Actually, I am saving the URL file to a local drive and then updating my workbook with this data. The problem is that the job that updates the URL file sometimes fails. I want to notify the user of my workbook that the data has not been update recently. I am trying to use the built in document properties (Last Save Time) but I cannot get it to work except for the workbook that has the macros in it. Is there a way to find the last save time of a workbook (from a URL address) seperate from the workbook that has the marco? Below is my current code that errors out at: dp = Application.Workbooks("DockReportExport.xls").BuiltinDocumentProperties("Last Save Time") with and runtime error.
Thanks for your help in advance!!!!
Sub FTP()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
'Open file from URL addres to check last save time
Workbooks.Open Filename:="http://172.16.1.94/Files/Operations/Dock/LoadBuilder/DockReportExport.xls"
'Check if data on server has been updated in the last 15 minutes
Dim dp
dp = Application.Workbooks("DockReportExport.xls").BuiltinDocumentProperties("Last Save Time")
Dim cd
cd = Now() '- 0.0104 '0.0104 = 15 minutes
ActiveWorkbook.Close SaveChanges:=False
If dp < cd Then 'ask if user wants to continue or stop
Response1 = MsgBox("Data on server has not been update since " & dp & "." _
& vbCr & "Select YES to continue using data from server." & vbCr _
& "Select NO to stop.", 4, "Old data on server!", 0, 0)
If Response1 = vbNo Then
goto 10
End if
End if
'download file from URL and save to local drive
Dim ret As Long
ret = URLDownloadToFile(0, "http://172.16.1.94/Files/Operations/Dock/LoadBuilder/DockReportExport.xls", "c:\LoadBuilder\DockReportExport.xls", 0, 0)
'Open local file and copy date to my workbook
Workbooks.Open Filename:="c:\LoadBuilder\DockReportExport.xls"
Range("$A:$BB").Select
Selection.Copy
Windows("Truck Builder.xls").Activate
Sheet10.Visible = xlSheetVisible
Sheets("Dock Report").Select
Range("B1").Select
ActiveSheet.Paste
Workbooks("DockReportExport.xls").Worksheets("Transport - Merge Report").Activate
Application.CutCopyMode = False
ActiveWindow.Close SaveChanges:=False
Sheets("TRUCK BUILDING").Select
Sheet10.Visible = xlSheetVeryHidden
Application.DisplayAlerts = True
Application.ScreenUpdating = True
10 End sub