中燃料场报表保存到文件--库存报表

Option Explicit


Sub CmdGroup3Save()

 '判断当前数据表是否为刚生产的库存报表

    If Range("A1") <> "工程材料盘点表" Then
        MsgBox "当前数据表不是 《工程材料盘点表》,请确认!"
        End '结束程序的运行
    End If

    
    '在桌面上创建需要保存文件的文件夹
    
    Dim mFolderPath As String
        mFolderPath = "C:\Users\Hlj\Desktop\出入库报表" + Format(Date, "m-d")
        
    If Dir(mFolderPath, vbDirectory) = "" Then
        MkDir mFolderPath
    End If


    '创建需要的报表文件
    Dim mFilePath As String
        mFilePath = mFolderPath + "\" + ThisWorkbook.Sheets("配置").Range("A1").Value + "-库存" + Format(Date, "m-d") + ".xlsx"
   
    '当前文件夹的名字
    Dim mFileName As String
    mFileName = ActiveWorkbook.Name

    '如果文件已经存在就删除已经存在的文件
    If Dir(mFilePath) <> "" Then
        Kill mFilePath
'        MsgBox "已经删除存在的文件"
    End If
    
    Dim mNewBook As Workbook
    Set mNewBook = Workbooks.Add
    With mNewBook
'        .Title = "All Sales"
'        .Subject = "Sales"
        .SaveAs Filename:=mFilePath
    End With
    
    'MsgBox mFileName

    '复制数据并保存
     Workbooks(mFileName).Sheets("料场库存明细").Cells.Copy ActiveWorkbook.Sheets("sheet1").Range("a1")
     ActiveWorkbook.Save
     ActiveWorkbook.Close

    MsgBox mFilePath + " 文件已经保存"

End Sub

 

你可能感兴趣的:(VBA)