HOW TO SAVE A FILE WITH A NAME BASED ON CELL TO SPECIFIC DRIVE

Use below code to in EXCEL by creating a VBA Code

VBA CODE 1

Private Sub CmdSaveThisWorkBook_Click()
Application.DisplayAlerts = False
        ThisWorkbook.SaveAs Filename:=Range("C4").Value & ":\" & Range("C3").Value & "(" & Format(Now(), "DD-MMM-YYYY hh mm AMPM") & ")" & ".xls", FileFormat:=56
Application.DisplayAlerts = True
End Sub



VBA CODE 2

Option Explicit

Sub saveWork()
Dim name As String
Worksheets("Sheet1").Select
Range("A1").Select  'change range here
name = Range("A1").Value  'change range here
ActiveWorkbook.SaveAs Filename:="E:\" & name, FileFormat:=50 'change path here

'            Format "xls": FileFormatValue = 56
'            Format "xlsx": FileFormatValue = 51
'            Format "xlsm": FileFormatValue = 52
'            Format "xlsb": FileFormatValue = 50


End Sub



VBA CODE 3

Sub FileNameAsCellContent()

Dim strFilename As String
Dim strpath As String

Application.DisplayAlerts = False

strpath = "C:\"
strFilename = Range("A1").Value & ".xlsx"

ActiveWorkbook.SaveAs strpath & strFilename, xlOpenXMLWorkbook

Application.DisplayAlerts = True

ActiveWorkbook.Close

End Sub





Comments

Popular posts from this blog

Formatting a Range of Cells In Excel VBA

Trunc() Function

BREAK THE PASSWORD OF THE SHEET IN EXCEL