J'ai un fichier xlsm qui est utilisé par beaucoup d'utilisateurs, j'ai ajouté une fonction de mise à jour qui doit vérifier sur un serveur si une nouvelle mise à jour du fichier xlsm est disponible, et si elle est disponible, il doit télécharger le fichier, puis écraser le fichier existant, certains comment je reçois une erreur écrire au fichier erreur 3004 peut-il quelqu'un peut-il m'aider avec elle? Laissez-moi vous expliquer mon code;VBA Ecrire un nouveau fichier dans le dossier Program Files
le fichier xlsm client a un chèque de nouveau bouton de mise à jour, lorsque l'utilisateur clique sur ce bouton, voici ce qui se passe,
Private Sub CommandButton5_Click()
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
'otherwise - carry on
Application.ScreenUpdating = False
Application.EnableCancelKey = xlDisabled
On Error GoTo ErrorProcedure
Application.Workbooks.Open ("http://www.mysite.com/Download/Update.xlsm")
'The book on the site opens and you can do whatever you
'want now (note that the remote book is "Read Only") - in
'this particular case a workbook_Open event now triggers
'a procedure to export the new file to the PC
ErrorProcedure:
MsgBox Err.Description
End Sub
puis le update.xlsm du serveur ouvre, et est le code ici;
Private Sub workbook_open()
Dim localfile As Date
Dim newfile As Date
localfile = FileDateTime("C:\Documents and Settings\localhost\Desktop\sample.xlsm")
newfile = "6/6/2013 4:00"
If DateDiff("s", localfile, newfile) > 0 Then
MsgBox "its closed"
Application.StatusBar = "contacting the download"
Dim myURL As String
myURL = "http://www.mysite.com/Download/sample.xlsm"
Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False
WinHttpReq.Send
Application.StatusBar = "waiting for the response"
myURL = WinHttpReq.ResponseBody
If WinHttpReq.Status = 200 Then
Application.DisplayAlerts = False
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.ResponseBody
oStream.SaveToFile ("C:\Documents and Settings\localhost\Desktop\sample.xlsm")
oStream.Close
End If
MsgBox "Update Completed"
Application.StatusBar = ""
Windows("Update.xlsm").Activate
ActiveWindow.Close
Application.DisplayAlerts = True
Else
MsgBox "There is no New Update"
Application.StatusBar = ""
End If
End Sub
Cette page peut intéresser et vous donner une approche quelque peu différente: http://www.excelguru.ca/content.php?152-Deploying-Add-ins-in-a-Network-Environment. –