Create New Workbook

fari1

Active Member
Joined
May 29, 2011
Messages
362
I want to save as my active sheet of current workbook as new file and new file name would be the Cell reference of active sheet.
this is urgent, waiting anxiously for the response plz
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
no, i mean that while next save, it must check if the first part of file name is matching with cell value, if it does, then replace that file else create a new one, e.g if the file name includes goog as cell value then while next time saving it must not create goog name file, it would be dulplicated
 
Upvote 0
Try this

Code:
Sub NewWB()
Dim p As String, q As String, r As String
p = ActiveWorkbook.Path
q = Sheets("prof").Range("C5").Value
If Not DirExists(p & "\Output") Then MkDir (p & "\Output")
r = Dir(p & "\Output\" & q & "*")
If r <> "" Then Kill p & "\Output\" & r
ActiveSheet.Copy
With ActiveWorkbook
    Application.DisplayAlerts = False
    .SaveAs Filename:=p & "\Output\" & q & " " & Format(Now, "dd-mm-yy hh-mm") & ".csv", FileFormat:=xlCSV
    Application.DisplayAlerts = True
    .Close savechanges:=True
End With
End Sub

Function DirExists(SDirectory As String) As Boolean
If Dir(SDirectory, vbDirectory) <> "" Then DirExists = True
End Function
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,865
Members
452,948
Latest member
UsmanAli786

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