简体   繁体   English

VBA:在特定目录上创建新工作簿

[英]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目录将是 Drive D:\\SALES_RFQ Database

WorkBook name is "MO Control Number Database"工作簿名称为“MO 控制编号数据库”

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提前致谢

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM