Save Workbook

VBA code to save workbook

Save Output 

Sub SaveOutput()

Dim FilePath As String
Dim FileName As String
Dim FileExtn As String
Dim wb As Workbook

Set wb = Thisworkbook

FilePath = wb.Sheets(1).Range("A4")
    'check if path is blank
    If FilePath = "" Then
        FilePath = wb.Path
    End If

    'check if path is incorrect
    If Dir(FilePath, vbDirectory) = "" Then
        FilePath = wb.Path
    End If

    'check \ at last of the path
    If Right(FilePath, 1) <> "\" Then
        FilePath = FilePath & "\"
    End If

FileName = wb.Sheets(1).Range("B4")
    'check if file name is blank
    If FileName = "" Then
        FileName = wb.Name & "_" & Format(Date, "ddmmyyyy")
    End If

FileExtn = Right(wb.Name, 5)

wb.SaveAs FileName:=FilePath & FileName & FileExtn, AccessMode:=xlShared

End Sub

टिप्पणी पोस्ट करें

0 टिप्पणियां