PDA

View Full Version : Solved: problems saveing two copies.



Ago
06-21-2008, 09:13 AM
im trying to make excel save my workbook in two harddrives.
i cant get it to run correct.



Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.SaveAs FileName:="C:\copy\" & ThisWorkbook.Name
End Sub



First of all, i dont want it to be SaveAs since i get a question if i want to replace the current file.
second problem, it crashes. thats a rather big problem.
it starts saving and then it says execl crashed bla bla bla, recreate the workbook and restart excel or something.

how do i fix this?

Oorang
06-21-2008, 10:02 AM
Option Explicit

Public Sub TestDoubleSave()
DoubleSave "P:\Backups\"
End Sub

Public Sub DoubleSave(secondaryPath As String)
Const strXLS_c As String = ".xls"
Const strBckSlsh_c As String = "\"
Const strFileFilter_c As String = "Microsoft Excel (*.xls),*.xls"
Dim strSavePath As String
If Not ThisWorkbook.Saved Then
If InStr(ThisWorkbook.FullName, strBckSlsh_c) Then
Excel.ThisWorkbook.Save
Else
strSavePath = Excel.Application.GetSaveAsFilename(FileFilter:=strFileFilter_c)
If strSavePath = "False" Then
Exit Sub
End If
Excel.ThisWorkbook.SaveAs strSavePath
End If
Excel.ThisWorkbook.SaveCopyAs secondaryPath & ThisWorkbook.Name
End If
End Sub

Ago
06-21-2008, 11:07 AM
thank you very much!!