Create new workbook with save as sheet

fari1

Active Member
Joined
May 29, 2011
Messages
362
i'm trying to do is create a workbook in csv and in its sheet1 i want to copy contents of my sheet "PROF" of original workbook and then save it with the name of CIK No. plus cell value of B5 and current date and time. below code is very raw form of what i'm trying to achieve, would appreciate any quick help on this. Also if there's any way that rather than copying of contents of my original workbook, the sheet is just saved as in new workbook. this would avoid memory leak and also clipboard will not be burdened.

Code:
Sub AddNewWBook()
        Dim XL As Excel.Application
        Dim str1 As Long
        Set XL = New Excel.Application
        XL.Workbooks.Add
        XL.Visible = True
        
        XL.ActiveWorkbook.Activate
        XL.Sheets(1).Select
        
        MkDir ThisWorkbook.Path & "\" & "CBG No."
        str1 = ""
        str1 = ThisWorkbook.Path & "\CBG No.\CBG No.&sheets("prof").Range("B5")"_" & DateTime.Day(Now) & "_" & DateTime.Month(Now) & "_" & DateTime.Year(Now) & "--" & DateTime.Hour(Now) & "_" & DateTime.Minute(Now) & "_" & DateTime.Second(Now) & ".xls"
        XL.ActiveWorkbook.SaveAs
        If Dir(str1) <> "" Then
            Cells(i, 6) = str1
        End If
        XL.ActiveWorkbook.Close True
        XL.Quit
        Set XL = Nothing
Next
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
hi thanks for the response, these codes are to open activeworkbook, while my workbook is already opened and also it doesn't serve my other purposes, will be glad if u assisst on it completely
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,628
Members
452,933
Latest member
patv

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