This article was previously published under Q254733
This article has been archived. It is offered "as is" and will no longer be updated.
When you save Excel workbooks that contain user forms, it typically takes about one minute to save to the local computer or within the local area network (LAN). When you save the same workbooks over a wide area network (WAN), it can take an excessive amount of time.
When Excel saves a user form, it writes out each control separately, and waits for an acknowledgement from the network before proceeding to the next control. The amount of time it takes to save is relative to the number of controls and user forms, and the network and remote drive latency.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:
For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMSTo work around this problem, the following Microsoft Visual Basic for Applications (VBA) macros copy the document to the local drive, and then share that local copy back to the WAN.
To implement the workaround, follow these steps:
Start Excel and open the VBA editor by pressing ALT+F11.
On the Insert menu, click Module.
Type the following code in the new module:
Option ExplicitPrivate Const TEMPFILE As String = "c:\dlocal.xls" 'Note, ensure the file path is valid.Private Const TEMPFILE2 As String = "c:\dlocal2.xls" 'Note, ensure the file path is valid.Private strOriginalName As StringPublic bSaving As BooleanPublic Sub SaveLocalThenCopy() Dim wbk As Workbook, wbk2 As Workbook Set wbk = ThisWorkbook If UCase(ThisWorkbook.FullName) <> UCase(TEMPFILE) Then strOriginalName = ThisWorkbook.FullName If Dir(TEMPFILE) <> "" Then Kill TEMPFILE If Dir(TEMPFILE2) <> "" Then Kill TEMPFILE2 ThisWorkbook.SaveAs TEMPFILE ThisWorkbook.SaveAs TEMPFILE2 FileCopy TEMPFILE, strOriginalName Set wbk2 = Workbooks.Open(strOriginalName) bSaving = False wbk.Close FalseEnd Sub
The following steps add code to the workbook's BeforeSave event to run the workaround above.
In the VBAProject window, double-click the ThisWorkbook icon to open the Code window.
At the top of this new Code window, there are two drop-down lists. In the Object (left) list, click Workbook; in the Procedure (right) list, click BeforeSave.
Type the following code in the Code window:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) If bSaving Then Cancel = False: Exit Sub Dim iAns As Integer iAns = MsgBox("Do you wish to Save As...?", vbYesNoCancel, "Save") Select Case iAns Case vbYes Cancel = True bSaving = True Application.Dialogs(xlDialogSaveAs).Show bSaving = False Exit Sub Case vbNo 'Do normal - local save. Case vbCancel Cancel = True Exit Sub End Select bSaving = True Cancel = True Application.OnTime Now + TimeValue("00:00:01"), "SaveLocalThenCopy"End Sub
Now, when you click Save As, Excel prompts you to choose either the default Excel Save As dialog box (click Yes), or to use the workaround above to save the document (click No).
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.
slow XL2000 XL97 userform