Excel VBA to export and save sheet as a new workbook that new workbook's name contains current date or time without formulas,.

Raastaa

New Member
Joined
Jan 24, 2023
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
I need a VBA code that helps me export an excel sheet and save it as an excel workbook without formulas,
and Name of new exported workbook should be contained old workbook name + current date or time.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try this one
VBA Code:
Sub WorkBook_New()
        Dim wk As Worksheet
        Dim oldWk As Workbook
        Set oldWk = ActiveWorkbook
        Dim WKName As String
        Dim SaveName As String
        Dim FilePath As String
        
        FilePath = "C:\Users\Windows\Desktop\"                                '  change file save path
        
        WKName = WorksheetFunction.Replace(oldWk.Name, InStr(1, oldWk.Name, ".x"), 95, "")
        SaveDes = FilePath & WKName & " " & Format(Now, "dd-mmm-yy HH,MM") & " hrs" & ".xlsx"
        oldWk.ActiveSheet.UsedRange.Copy
        

        Set wk = Workbooks.Add.Sheets(1)
        wk.Range("A1").PasteSpecial xlPasteValues
        wk.SaveAs SaveDes, 51
        
End Sub
 
Upvote 0
Hii Raastaa,

what about this for a start:

VBA Code:
Public Sub MrE_1227869_170180F()
' https://www.mrexcel.com/board/threads/excel-vba-to-export-and-save-sheet-as-a-new-workbook-that-new-workbooks-name-contains-current-date-or-time-without-formulas.1227869/
' Created: 20230124
' By:      HaHoBe
Dim wbThis As Workbook

Set wbThis = ThisWorkbook
wbThis.ActiveSheet.Copy
With ActiveWorkbook
  With .ActiveSheet.UsedRange
    .Value = .Value
  End With
  .SaveAs wbThis.Path & Application.PathSeparator & Left(wbThis.Name, InStrRev(wbThis.Name, ".") - 1) & Format(Now, "_yymmdd_hhmmss") & _
        ".xlsx", FileFormat:=51
  .Close False
End With
Set wbThis = Nothing
End Sub

It takes the ActiveSheet from the workbook with code and saves to folder of workbook with code as macrofree workbook.

Ciao,
Holger
 
Upvote 0

Forum statistics

Threads
1,215,778
Messages
6,126,841
Members
449,343
Latest member
DEWS2031

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