PathFinder
PathFinder

Reputation: 27

VBA: Create New Workbook on a specific Directory

I would like to create a new workbook on a specific directory using a button from an activeworkbook.

Directory will be Drive D:\SALES_RFQ Database

WorkBook name is "M.O Control Number Database"

Condition: The code has to check if the workbook does exists, if not, if has to create the workbook on the given directory.

Any help with much appreciated. Thanks in advance

Upvotes: 0

Views: 10691

Answers (1)

Error 1004
Error 1004

Reputation: 8220

Option Explicit

Sub test()

    Dim Path As String, DocName As String

    Path = "D:\SALES_RFQ Database"
    DocName = "M.O Control Number Database"

    If Dir(Path & "\" & DocName & ".xlsx") = "" Then
        Workbooks.Add
        ActiveWorkbook.SaveAs Path & "\" & DocName & ".xlsx"

    End If

End Sub

Upvotes: 4

Related Questions