YasserKhalil
Well-Known Member
Can you help me with that point please?
What do you mean near a gas factory ..? Is it too bad you mean?
What do you mean near a gas factory ..? Is it too bad you mean?
SaveSetting
- GetSetting
- DeleteSetting
like you can - must - see in the VBA help).SaveSetting "YourProjectName", "Workbook", "Old", "C:\Folder\Workbook.xlsm"
…F = GetSetting("YourProjectName", "Workbook", "Old")
If F > "" Then
DeleteSetting "YourProjectName", "Workbook"
End If
Private Declare PtrSafe 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
Dim currVer As Single
Private Sub Workbook_Open()
Dim objReq As MSXML2.ServerXMLHTTP60
Dim oApp As Object
Dim dlPath As Variant
Dim sFile As String
Dim strResponse As String
Dim wbHelper As String
Const sURL As String = "https://docs.google.com/document/d/e/2PACX-1vSnj9bynjBnlLyr60ExmmXWD1b-_qgfatglmDhLhIQaHM_8EvXC0zucOsWlLIlSfhyDUuuAWrRhWnF7/pub"
currVer = 0.5
Set objReq = New ServerXMLHTTP60
With objReq
.Open "GET", sURL, False
.send
If .Status = 200 Then
strResponse = .responseText
If Val(Trim(Split(Split(strResponse, "Version:")(1), "</span>")(0))) > currVer Then
If MsgBox("You Have Newer Version. Would You Like To Download It?", vbYesNo + vbQuestion) = vbYes Then
dlPath = Environ("PROGRAMDATA") & "\MyFolder\"
sFile = "MyFiles.zip"
If Len(Dir(dlPath & "*.*")) > 0 Then Kill dlPath & "*.*"
If Len(Dir(dlPath, vbDirectory)) = 0 Then MkDir dlPath
URLDownloadToFile 0, Trim(Replace(Split(Split(strResponse, "Link:")(1), "</span>")(0), "open", "uc") & "&export=download"), dlPath & sFile, 0, 0
Set oApp = CreateObject("Shell.Application")
oApp.Namespace(dlPath).CopyHere oApp.Namespace(dlPath & sFile).items
SaveSetting "MyProjectEntry", "Workbook", "Old", ThisWorkbook.FullName
wbHelper = dlPath & "\TempWorkbook.xlsm"
If Dir(wbHelper) > "" Then
Workbooks.Open wbHelper
ThisWorkbook.Close False
Else
MsgBox "Update Not Completed. Make Sure " & wbHelper & " Exists", vbCritical
End If
End If
End If
End If
.abort
End With
End Sub
SaveSetting "MyProjectEntry", "Workbook", "Old", ThisWorkbook.FullName
Private Sub Workbook_Open()
Dim sOldWorbook As String
sOldWorbook = GetSetting("MyProjectEntry", "Workbook", "Old")
Workbooks(Split(sOldWorbook, "\")(UBound(Split(sOldWorbook, "\")))).Close False
MsgBox "OK"
Stop
End Sub
Workbooks(Split(sOldWorbook, "\")(UBound(Split(sOldWorbook, "\")))).Close False
Version: 1.0
Link: https://drive.google.com/open?id=1f81uCVN0XYofvO8dRHWxa5KL_hy_fOgp
Option Explicit
Private Declare PtrSafe 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
Dim currVer As Single
Private Sub Workbook_Open()
Dim objReq As MSXML2.ServerXMLHTTP60
Dim oApp As Object
Dim dlPath As Variant
Dim sFile As String
Dim strResponse As String
Dim wbHelper As String
Const sURL As String = "https://docs.google.com/document/d/e/2PACX-1vSnj9bynjBnlLyr60ExmmXWD1b-_qgfatglmDhLhIQaHM_8EvXC0zucOsWlLIlSfhyDUuuAWrRhWnF7/pub"
dlPath = Environ("PROGRAMDATA") & "\MyFolder\"
On Error Resume Next
If Len(Dir(dlPath & "*.*")) > 0 Then Kill dlPath & "*.*": RmDir dlPath
If Len(Dir(Environ("TEMP") & "\TempWorkbook.xlsm")) > 0 Then Kill Environ("TEMP") & "\TempWorkbook.xlsm"
DeleteSetting "MyProjectEntry"
On Error GoTo 0
currVer = 1
Set objReq = New ServerXMLHTTP60
With objReq
.Open "GET", sURL, False
.send
If .Status = 200 Then
strResponse = .responseText
If Val(Trim(Split(Split(strResponse, "Version:")(1), "</span>")(0))) > currVer Then
If MsgBox("You Have Newer Version. Would You Like To Download It?", vbYesNo + vbQuestion) = vbYes Then
sFile = "MyProjectFiles.zip"
If Len(Dir(dlPath, vbDirectory)) = 0 Then MkDir dlPath
URLDownloadToFile 0, Trim(Replace(Split(Split(strResponse, "Link:")(1), "</span>")(0), "open", "uc") & "&export=download"), dlPath & sFile, 0, 0
Set oApp = CreateObject("Shell.Application")
oApp.Namespace(dlPath).CopyHere oApp.Namespace(dlPath & sFile).items
With CreateObject("Scripting.Filesystemobject")
If .FileExists(dlPath & "TempWorkbook.xlsm") Then .MoveFile dlPath & "TempWorkbook.xlsm", Environ("TEMP") & "\TempWorkbook.xlsm"
End With
SaveSetting "MyProjectEntry", "Workbook", "Old", ThisWorkbook.FullName
wbHelper = Environ("TEMP") & "\TempWorkbook.xlsm"
If Dir(wbHelper) > "" Then
Workbooks.Open wbHelper
Else
MsgBox "Update Not Completed. Make Sure " & wbHelper & " Exists", vbCritical
End If
End If
End If
End If
.abort
End With
End Sub
Private Sub Workbook_Open()
Application.OnTime Now + TimeSerial(0, 0, 1), "CloseOldProject"
End Sub
Option Explicit
Const sNewWorkbook = "C:\ProgramData\MyFolder\MyProject.xlsm"
Sub CloseOldProject()
Dim sOldWorbook As String
sOldWorbook = GetSetting("MyProjectEntry", "Workbook", "Old")
Workbooks(Split(sOldWorbook, "\")(UBound(Split(sOldWorbook, "\")))).Close False
If Dir(sNewWorkbook) > "" Then CreateObject("Scripting.FileSystemObject").CopyFile sNewWorkbook, sOldWorbook
Workbooks.Open (sOldWorbook)
With ThisWorkbook
.Save
.ChangeFileAccess Mode:=xlReadOnly
Kill .FullName
.Close SaveChanges:=False
End With
End Sub