Save Sheet w/extra features

FoRmEd

Board Regular
Joined
Jan 29, 2011
Messages
72
Hello everyone:

I located the following codes on our site and would like to merge them all and add just one more thing.

First I want to save a single sheet:

Code:
Sub savesheet2()
Application.ScreenUpdating = False
ActiveSheet.Select
ActiveSheet.Copy
ThisFile = Range("A1").Value
ActiveSheet.SaveAs Filename:="C:temp" & ThisFile & ".xls"
Application.ScreenUpdating = True
ActiveWorkbook.Close
End Sub

Then, if the destination folder doesn't exist, it needs to be created.

Code:
Function fileexists(f As String) As Boolean
If Not f = vbNullString Then fileexists = True
 
End Function

Lastly I want it to create a custom save as name "PHZ2[todays date].xls"
"today's date" would be pulled from a populated cell like N1

Code:
no code just yet

Your help is in merging these is much appreciated;)
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try

Code:
Sub savesheet2()
Application.ScreenUpdating = False
ActiveSheet.Copy
If Not DirExists("C:\temp") Then MkDir "C:\temp"
ActiveSheet.SaveAs Filename:="C:\temp\" & "PHZ2 " & Format(Date, "mm-dd-yyyy") & ".xls", FileFormat:=56
Application.ScreenUpdating = True
ActiveWorkbook.Close
End Sub


Function DirExists(SDirectory As String) As Boolean
DirExists = Dir(SDirectory, vbDirectory) <> ""
End Function
 
Upvote 0
It won't create the new directory. Then I skipped that debug and got a runtime-error 104 on the code below.
Code:
ActiveSheet.SaveAs FileName:="I:\backup\PHZ2\" & "PHZ2 " & Format_
(Date, "mm-dd-yyyy") & ".xls", FileFormat:=56
 
Upvote 0
Working here. Try without the fileformat argument

Code:
Sub savesheet2()
Application.ScreenUpdating = False
ActiveSheet.Copy
If Not DirExists("C:\temp") Then MkDir "C:\temp"
ActiveSheet.SaveAs Filename:="C:\temp\" & "PHZ2 " & Format(Date, "mm-dd-yyyy") & ".xls"
Application.ScreenUpdating = True
ActiveWorkbook.Close
End Sub


Function DirExists(SDirectory As String) As Boolean
DirExists = Dir(SDirectory, vbDirectory) <> ""
End Function
 
Upvote 0
Thank you very much for the help, your dedication doesn't go unnoticed:)
Pulled out the (FileFormat:=56) and now getting

Run-time error '76'
Path not found

I'm going to read-up on this error; try and understand it by the time you post, so I will your code :)

I had a quick idea but it failed. I thought the workbook being password protected would effect it so I added the respective code below (this didn't fix the run-time error). And below that is what the code looks like now.

Code:
     ActiveSheet.Unprotect Password:="****"
   'code going here
     ActiveSheet.Protect Password:="****"
Code:
Sub savesheet2()
ActiveSheet.Unprotect Password:="****"
Application.ScreenUpdating = False
ActiveSheet.Copy
If Not DirExists("I:\backup\PHZ2") Then MkDir "I:\backup\PHZ2"
ActiveSheet.SaveAs FileName:="I:\backup\PHZ2\" & "PHZ2 " & Format(Date, "mm-dd-yyyy") & ".xls"
Application.ScreenUpdating = True
ActiveWorkbook.Close
ActiveSheet.Protect Password:="*****"
End Sub
 
Function DirExists(SDirectory As String) As Boolean
DirExists = Dir(SDirectory, vbDirectory) <> ""
End Function
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,876
Members
452,949
Latest member
Dupuhini

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