Thread: Network problem
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Incidental Incidental is offline
external usenet poster
 
Posts: 226
Default Network problem

Hi oldjay

This method is perhaps not the easiest or cleanest way round your
problem though it should work for your problem it works by checking
the vbproject description against a single line textfile if the values
match you have the latest version if not another workbook is opened
that will close the book "qq2.xls" and run the code to copy the latest
version from the server.

to set this up create a notepad text file and place it in the same
directory as your latest version of the workbook "\\server3\Quotes
\qq2.xls" in this file write your version number i.e. "1.2.3"

In the local directory "C:\Qoutes\" create a new workbook and add the
2 modules to it then paste the following code in to them.

'module1
'this code will switch between workbooks so the file you want to
update isn't open when you update

Option Explicit

Sub CloseMyApp(inBook As Workbook) 'Close MyApp workbook then run the
updater sub
Application.OnTime Now + TimeValue("00:00:02"), "Install_Update"
inBook.Close False
End Sub

'module2
'this code will copy the latest version to the local computer

Option Explicit
Dim ObjFso As Object
Dim Copy_Dir As String
Dim Paste_Dir As String

Sub Install_Update()

Copy_Dir = "\\server3\Quotes" 'Pass location to a string

Paste_Dir = "C:\Qoutes" 'Pass destination to a string

Set ObjFso = CreateObject("Scripting.FileSystemObject")

ObjFso.CopyFolder Copy_Dir, Paste_Dir 'Copy the
contacts system to the local drive

MsgBox "My Application" & vbNewLine & "Has Been Updated" &
vbNewLine & _
"Please restart My Application", vbOKOnly, "DownLoaded"

ActiveWorkbook.Saved = True 'Ensure Excel doesn't ask to save
the workbook

Set ObjFso = Nothing

Application.Quit 'Quit Excel

End Sub

Then in your main workbook "qq2.xls" you should add your version
number to the vbproject description (under VBA project properties from
the tools menu of VBE)

Once you have set your version number make sure your textfile has the
same version number and then in the workbook open module of qq2.xls
add the following code.

Option Explicit

Dim ObjFSO As Object
Dim ObjTxt As Object
Dim TxtVal As String
Const TxtChk = "\\server3\Quotes\New Text Document.txt"
Const ForReading = 1

Private Sub Workbook_Open()

Dim Msg, Style, Title, Response

Msg = "Do you want to check for an update?"
Style = vbYesNo + vbDefaultButton2
Title = "Check for Update"

Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then

Set ObjFSO = CreateObject("Scripting.FileSystemObject")

Set ObjTxt = ObjFSO.OpenTextFile(TxtChk, ForReading)

TxtVal = ObjTxt.ReadLine

ObjTxt.Close

If TxtVal = ThisWorkbook.VBProject.Description Then

MsgBox ("Current version is up to date")

Exit Sub

Else
'Load updater workbook
Workbooks.Open ("C:\Qoutes\Updater.xls")
'Run the sub to close this workbook
Application.Run "'Updater.xls'!CloseMyApp", ThisWorkbook

End If

Else

Exit Sub

End If

End Sub

And that should be it. It will take a bit of manual work to get the
files onto the local machines but from then on it should be a matter
of you updating the file CHANGING BOTH VERSION NUMBERS vbproject
description and the text file then the user should be able to update
it for themselves. You will have to tinker with the code I'm sure to
get it to fit with your specific needs and I'm sure that the directory
information will need to be checked. I recommend that you test the
code first before using as it will copy over the qq2.xls file without
prompt.

Any how I hope this is of some help to you

S