Hi Ken, Killian,
I finally got time to try all this out, after MUCH "playing around" it turned out to be remarkably simple.
You CAN use a "Workbook_Open event, also, there's no need to set any references and there's not even a need to use Internet Explorer, you just access the remote book with this:
'put your own path here
The full code has been submitted for KB approval. A short uncommented copy here FYI:[vba]
'In workbook on PC
Option Explicit
Sub BeamMeUpScotty()
Dim Answer As VbMsgBoxResult, N%, MyFile$
Answer = MsgBox("1) You need to be on-line to update" & vbLf & _
"2) The update may take a few minutes" & vbLf & _
"3) Please do not interrupt the process once started" & vbLf & _
"" & vbLf & _
"SEARCH FOR UPDATE?", vbYesNo, "Update?")
If Answer = vbNo Then Exit Sub
Application.ScreenUpdating = False
Application.EnableCancelKey = xlDisabled
On Error GoTo ErrorProcedure
Application.Workbooks.Open ("http://www.geocities.com/johnske100" & _
"/HookToMySite_MASTER.xls")
Workbooks("HookToMySite_MASTER.xls").Close savechanges:=False
MyFile = Dir(ActiveWorkbook.Path & "\Version101.bas")
If MyFile = Empty Then
MsgBox "No new file found" '< (download failed)
Else
With ActiveWorkbook.VBProject
For N = 1 To .VBComponents.Count
If .VBComponents(N).Name = "Version101" Then
MsgBox "Sorry, there are no later versions available", _
, "Already Using Current Version..."
Exit Sub
ElseIf .VBComponents(N).Name = "Version100" Then
.VBComponents.Remove .VBComponents(N)
MsgBox "Old file removed"
Exit For
End If
Next N
End With
Application.VBE.ActiveVBProject.VBComponents _
.Import (ActiveWorkbook.Path & "\Version101.bas")
MsgBox "Version upgrade complete..."
End If
Run ("NewModuleV101")
ActiveWorkbook.Save
Exit Sub
ErrorProcedure:
MsgBox Err.Description
End Sub
'this goes into the book on the site
Option Explicit
'This code is triggered by a Workbook_Open event
Sub ExportModule()
Dim MyFile$, N%
Workbooks("HookToMySite_slave.xls").Activate
MyFile = Dir(ActiveWorkbook.Path & "\Version101.bas")
If MyFile = Empty Then
With ThisWorkbook.VBProject
For N = 1 To .VBComponents.Count
If .VBComponents(N).Name = "Version101" Then
Application.VBE.ActiveVBProject.VBComponents(N) _
.Export (ActiveWorkbook.Path & "\Version101.bas")
Exit For
End If
Next N
End With
Else
MsgBox "No later version is available", , "Already updated..."
End If
End Sub