Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Well I just thought I was so clever as a non-programmer spending two
days writing this macro to save the current worksheet to two different locations BUT ... It worked fine in the workbook I wrote it in, then I learned that if I put it in personal.xls all my workbooks could use it. I managed that but now it backs up personal.xls not the workbook I execute it from. I assume there is some way to reference the current workbook from a macro living within personal.xls? Also I suspect that there is a much better way to do this than doing three saves? Thanks ----------------------- Sub CopyToTwoLocations() Dim strFileA As String Dim strFileB As String Dim strFileC As String 'Save first just to be safe ThisWorkbook.Save 'Save the name of the current doc strFileA = ThisWorkbook.Name 'Capture the name of the current doc before the 'SveAs' changes it strFileC = ThisWorkbook.FullName 'Define backup paths strFileB = "C:\My Documents\SaveToTwoLocations\" & strFileA strFileB2 = "H:\SaveToTwoLocations\" & strFileA 'Save backups Application.DisplayAlerts = False ' Avoid msg for overwites ThisWorkbook.SaveAs Filename:=strFileB On Error GoTo MyError 'In case back up drive is off-line ThisWorkbook.SaveAs Filename:=strFileB2 'Set the current (active) doc back to the original ThisWorkbook.SaveAs Filename:=strFileC Application.DisplayAlerts = True Exit Sub MyError: MsgBox "Backup to flash apparently failed" ThisWorkbook.SaveAs Filename:=strFileC Application.DisplayAlerts = True End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Active cell as a reference to open a worksheet | Excel Worksheet Functions | |||
Altering code to reference the worksheet before the active worksheet | Excel Programming | |||
Assigning a macro to a worksheet (vs personal.xls) | Excel Programming | |||
How to end macro on inital active worksheet containing macro button that was clicked | Excel Programming | |||
macro to apply worksheet event to active worksheet | Excel Programming |