LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Reference active worksheet from macro in personal.xls

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Active cell as a reference to open a worksheet LaDdIe Excel Worksheet Functions 6 March 15th 07 07:06 PM
Altering code to reference the worksheet before the active worksheet KimberlyC Excel Programming 8 March 15th 05 10:26 PM
Assigning a macro to a worksheet (vs personal.xls) Bridget[_3_] Excel Programming 4 May 15th 04 07:22 PM
How to end macro on inital active worksheet containing macro button that was clicked Silverhawk1 Excel Programming 2 May 14th 04 03:58 PM
macro to apply worksheet event to active worksheet Paul Simon[_2_] Excel Programming 3 August 7th 03 02:50 AM


All times are GMT +1. The time now is 11:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"