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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try

Code:
Sub NewWB()
ActiveSheet.Copy
With ActiveWorkbook
    .SaveAs Filename:=ActiveSheet.Name & ".xls"
    .Close
End With
End Sub
 
Upvote 0
hi vog, thanks for the reply, the sheet that it is copying, contains a macro, so it is asking if i want to say it as macro enabled workbook, so i want to get rid of this msg,as it would be macro free workbook. Also i want to name the file as "\Output&sheets(prof).range("C5").value_" & DateTime.Day(Now) & "_" & DateTime.Month(Now) & "_" & DateTime.Year(Now) & "--" & DateTime.Hour(Now) & "_" & DateTime.Minute(Now) & "_" & DateTime.Second(Now) & ".csv"

as the file created would be in csv format, also the file creation is the part of the loop, so i also want to add in the code that it must check if the file of that cell value name already exisits or not, if it does then simply replace the file, else create the new one.
i hope i didn't confuse u
 
Upvote 0
Try like this

Code:
Sub NewWB()
Dim p As String, q As String
p = ActiveWorkbook.Path
q = Sheets("prof").Range("C5").Value
ActiveSheet.Copy
With ActiveWorkbook
    Application.DisplayAlerts = False
    .SaveAs Filename:=p & "\Output\" & q & Format(Now, "dd-mm-yy hh-ss") & ".csv", FileFormat:=xlCSV
    Application.DisplayAlerts = True
    .Close
End With
End Sub
 
Upvote 0
it is highlighting this part of the code

Code:
    .SaveAs Filename:=p & "\Output\" & q & Format(Now, "dd-mm-yy hh-ss") & ".csv", FileFormat:=xlCSV

method save as of worksheet object falied
 
Upvote 0
Okayz, i didn't created the folder, i just created, yes it works, can't it create the folder by itself? just one time for the whole loop?
also it is asking if i want to save the changes in the new workbook? why is that so? and i asked u also that it must match the cell referece for the next save,if the file that includes that cell name already exists, then it must exit else create new one. is that possible?
 
Upvote 0
Try this

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

its highlighting this part and saying function not defined
 
Upvote 0
Oops! I accidentally didn't post the whole code

Code:
Sub NewWB()
Dim p As String, q As String
p = ActiveWorkbook.Path
q = Sheets("prof").Range("C5").Value
If Not DirExists(p & "\Output") Then MkDir (p & "\Output")
ActiveSheet.Copy
With ActiveWorkbook
    Application.DisplayAlerts = False
    .SaveAs Filename:=p & "\Output\" & q & " " & Format(Now, "dd-mm-yy hh-ss") & ".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,603
Messages
6,179,853
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