macro problem

d0wnt0wn

Well-known Member
Joined
Oct 28, 2002
Messages
771
hi... I made this macro to save a file based on the name in a cell but i get

a runtime 1004 error method 'savea' of object_workbook failed if there is already a file of that name in the folder and i select no or cancel instead of yes.... any way to fix that???

also... is it possible to save just the active worksheet to a location and not the whole workbook?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try something like this:
Code:
Sub Whaterver()
On Error GoTo userC

'your code here
'
'
'
Exit Sub

userC:
MsgBox "User Cancelled, File Not Saved!"
Exit Sub

End Sub

HTH.
 
Upvote 0
If you want to save just one worksheet, you need your macro to copy the sheet into a new workbook and save that.

Here's an example. Keep in mind that the "Copy" method of a worksheet automatically creates a new workbook with the copied sheet when you don't specify the Before or After arguments, and that new workbook is the ActiveWorkbook until another one is activated or it's closed:

Code:
Sub SaveActiveSheet()
    
    ActiveSheet.Copy
    
    ActiveWorkbook.SaveAs Filename:="C:\test.xls"
    
    ActiveWorkbook.Close

End Sub
 
Upvote 0
Hi, d0wnt0wn,
second question
is it possible to save just the active worksheet to a location and not the whole workbook?
ActiveSheet.Copy
this makes a new file of the sheet which you can then save ...
Activeworkbook.Save or Saveas ...
kind regards,
Erik
 
Upvote 0
ok heres how it went.... martinee.... the code worked very well except.... is there a way that i can have the user be given the option to name it something else rather than just close the workbook......

Scifibum....... worked like a charm thanks
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,409
Members
448,959
Latest member
camelliaCase

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top