Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Save copy of workbook

I need to save a duplicate copy of a workbook each time it is saved,
overwritting the duplicate. I tried this code and it did not work. No
errors but it did not create the copy.

Private Sub Worksheet_beforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.SaveCopyAs "g:\EHSAdr.xls"
End Sub

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Save copy of workbook

When you go into the VBE, double click on the ThisWorkbook object (in the
project explorer).

Then use the dropdowns at the top of the code window and choose Workbook. Then
use the righthand side dropdown to choose BeforeSave, you'll see that the event
isn't what you called it.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

You can't make events up, so it's much better/safer to use those dropdowns to
get the correct event and arguments.

Marnie wrote:

I need to save a duplicate copy of a workbook each time it is saved,
overwritting the duplicate. I tried this code and it did not work. No
errors but it did not create the copy.

Private Sub Worksheet_beforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.SaveCopyAs "g:\EHSAdr.xls"
End Sub

Thanks!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Save copy of workbook

Dave
Thanks! That worked for a regular file name. However I am actually trying
to update a document on a Sharepoint site so the path name is a web address.
If I manually do a Save AS with the web address it works fine. If I put the
same web address in this code I get "Run-time error 1004. The file cannot be
found." Do you know if there is a limit to the number of characters that can
be used in a file name in this context?

Thanks
Marni

"Dave Peterson" wrote:

When you go into the VBE, double click on the ThisWorkbook object (in the
project explorer).

Then use the dropdowns at the top of the code window and choose Workbook. Then
use the righthand side dropdown to choose BeforeSave, you'll see that the event
isn't what you called it.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

You can't make events up, so it's much better/safer to use those dropdowns to
get the correct event and arguments.

Marnie wrote:

I need to save a duplicate copy of a workbook each time it is saved,
overwritting the duplicate. I tried this code and it did not work. No
errors but it did not create the copy.

Private Sub Worksheet_beforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.SaveCopyAs "g:\EHSAdr.xls"
End Sub

Thanks!


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Save copy of workbook

I will try that. Thanks!

"Dave Peterson" wrote:

I don't know anything about Sharepoint or how to save to a web location, but if
I recall correctly (and I may be in error), you're limited to 255 or 256
characters in the path.

Maybe you could experiment by making a few test folders and see when it blows
up.

Marnie wrote:

Dave
Thanks! That worked for a regular file name. However I am actually trying
to update a document on a Sharepoint site so the path name is a web address.
If I manually do a Save AS with the web address it works fine. If I put the
same web address in this code I get "Run-time error 1004. The file cannot be
found." Do you know if there is a limit to the number of characters that can
be used in a file name in this context?

Thanks
Marni

"Dave Peterson" wrote:

When you go into the VBE, double click on the ThisWorkbook object (in the
project explorer).

Then use the dropdowns at the top of the code window and choose Workbook. Then
use the righthand side dropdown to choose BeforeSave, you'll see that the event
isn't what you called it.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

You can't make events up, so it's much better/safer to use those dropdowns to
get the correct event and arguments.

Marnie wrote:

I need to save a duplicate copy of a workbook each time it is saved,
overwritting the duplicate. I tried this code and it did not work. No
errors but it did not create the copy.

Private Sub Worksheet_beforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.SaveCopyAs "g:\EHSAdr.xls"
End Sub

Thanks!

--

Dave Peterson


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Save copy of workbook

I got it to work by using SaveAs instead of SaveCopyAs. I also had to change
it to the BeforeClose event. In the BeforeSave event it saved the copy but
not the original file.

Thanks for your help!

"Marnie" wrote:

I will try that. Thanks!

"Dave Peterson" wrote:

I don't know anything about Sharepoint or how to save to a web location, but if
I recall correctly (and I may be in error), you're limited to 255 or 256
characters in the path.

Maybe you could experiment by making a few test folders and see when it blows
up.

Marnie wrote:

Dave
Thanks! That worked for a regular file name. However I am actually trying
to update a document on a Sharepoint site so the path name is a web address.
If I manually do a Save AS with the web address it works fine. If I put the
same web address in this code I get "Run-time error 1004. The file cannot be
found." Do you know if there is a limit to the number of characters that can
be used in a file name in this context?

Thanks
Marni

"Dave Peterson" wrote:

When you go into the VBE, double click on the ThisWorkbook object (in the
project explorer).

Then use the dropdowns at the top of the code window and choose Workbook. Then
use the righthand side dropdown to choose BeforeSave, you'll see that the event
isn't what you called it.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

You can't make events up, so it's much better/safer to use those dropdowns to
get the correct event and arguments.

Marnie wrote:

I need to save a duplicate copy of a workbook each time it is saved,
overwritting the duplicate. I tried this code and it did not work. No
errors but it did not create the copy.

Private Sub Worksheet_beforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.SaveCopyAs "g:\EHSAdr.xls"
End Sub

Thanks!

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Save copy of workbook

You may want to try .savecopyas in the beforesave event once more.

Marnie wrote:

I got it to work by using SaveAs instead of SaveCopyAs. I also had to change
it to the BeforeClose event. In the BeforeSave event it saved the copy but
not the original file.

Thanks for your help!

"Marnie" wrote:

I will try that. Thanks!

"Dave Peterson" wrote:

I don't know anything about Sharepoint or how to save to a web location, but if
I recall correctly (and I may be in error), you're limited to 255 or 256
characters in the path.

Maybe you could experiment by making a few test folders and see when it blows
up.

Marnie wrote:

Dave
Thanks! That worked for a regular file name. However I am actually trying
to update a document on a Sharepoint site so the path name is a web address.
If I manually do a Save AS with the web address it works fine. If I put the
same web address in this code I get "Run-time error 1004. The file cannot be
found." Do you know if there is a limit to the number of characters that can
be used in a file name in this context?

Thanks
Marni

"Dave Peterson" wrote:

When you go into the VBE, double click on the ThisWorkbook object (in the
project explorer).

Then use the dropdowns at the top of the code window and choose Workbook. Then
use the righthand side dropdown to choose BeforeSave, you'll see that the event
isn't what you called it.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

You can't make events up, so it's much better/safer to use those dropdowns to
get the correct event and arguments.

Marnie wrote:

I need to save a duplicate copy of a workbook each time it is saved,
overwritting the duplicate. I tried this code and it did not work. No
errors but it did not create the copy.

Private Sub Worksheet_beforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.SaveCopyAs "g:\EHSAdr.xls"
End Sub

Thanks!

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
Reply
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
how to save a copy of personal workbook? Janis Excel Discussion (Misc queries) 1 July 27th 07 12:09 AM
Trying to use VBA to save a copy of a workbook kfell Excel Discussion (Misc queries) 2 March 23rd 07 12:36 PM
Use a Macro to Save a Copy of a Workbook? Joe D[_4_] Excel Programming 3 July 14th 05 03:29 PM
Save a copy of a Workbook without its modules Jordi Pocurull Excel Programming 1 September 7th 04 01:14 PM
copy 3 sheets & save them into new workbook shital Excel Programming 1 October 17th 03 12:22 PM


All times are GMT +1. The time now is 07:38 PM.

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

About Us

"It's about Microsoft Excel"