473,387 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Save a duplicate copy in excel using VBA

For some reason, excel stops working when I use this code...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
  2.  
  3. ThisWorkbook.SaveAs "C:\Users\Me\Desktop\test2\test2.xlsm"
  4.  
  5. End Sub
  6.  

What I am trying to do is save a duplicate copy of my workbook in another location. Is there maybe another way to go about doing this? I am really new to VBA so odds are I'm making mistakes here and there. Any help or direction would be greatly appreciated :)

Thanks
Aug 2 '10 #1
1 1873
Stewart Ross
2,545 Expert Mod 2GB
Hi. You are trying to use the BeforeSave event of the workbook to try to save the current workbook to a new location. This can't work, as BeforeSave is triggered every time you try to save the workbook and it will try again to save a copy, triggering itself once again, and leading to an infinite regression of incomplete save events locking the whole application!

If you want to save a duplicate copy you will need an entirely different approach. Bear in mind that the name you give to SaveAs is the name of that workbook thereafter - it does not save a duplicate copy as such.

You would need to design a bespoke replacement for the existing File Save and SaveAs methods. Aside from placing a new Save button on your application you would need to use the BeforeSave event as the trigger for your new events too, by cancelling the normal file save and redirecting code execution to your new routines. I think this task is likely to prove too much of a challenge given that you have limited experience in VBA, and I would advise you not to go down this route at present.

-Stewart
Aug 6 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: barma16 | last post by:
I've hit a bit of a brick wall here, and could use some advice. I have an Access application whose output is a four-tab Excel spreadsheet where three of the four tabs are the result of database...
3
by: yaya via DotNetMonster.com | last post by:
Hi, I'm using OleDb to read an excel files and display the data in a datagrid (using dataset as data source), after modifying the data on datagird, how can I save the changes back into Excel files. ...
2
by: Bill nguyen | last post by:
How can I open an Excel file then SAVE AS .CSV file using VB.NET? Thanks Bill
1
by: winmani | last post by:
hi buddies, cud u explain, how to retrieve data from excel file and save into oracle database using vb.net.
0
by: Fab117 | last post by:
Hello, When I write a word document, I have to put it in a common share For security I would like to always do a copy of it in my folder. I did it without trouble for my Excel workooks with :...
1
slapshock
by: slapshock | last post by:
Hi good day Please help me with my problem i want to save my data into excel using vb.net but i have no idea on how to do it i search in the internet but i couldnt found the answer... Please...
1
by: Invicta | last post by:
There are two fields I need to copy preferably using a command button. If possible I would also like to stipulate how many new records I want. I've made a start using the in built Duplicate Record...
2
by: ranjiths | last post by:
hi, i am trying to export data to excel from html using javascript, but i am getting an error as it opens saveas window. Please do the needful
11
by: Adrian | last post by:
Is it possible to save a copy of cout the same way you can save a copy of stdout in C (I know C version is portable, but unix portable is good enough for me). I have to use a library which...
3
by: qfchen | last post by:
Hi In order to save data into excel file in my application, I need to define Dim excelApp As New Excel.Application but I got error message: "Type Excel.Application" is not defined. What component...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.