Nguyễn Văn Khuyến
Nguyễn Văn Khuyến
Thảo luận 1 thảo luận
Vỗ tay 0 vỗ tay
Lượt xem 473 lượt xem

Em muốn tạo ra một workbook mới và tự động lưu vào đường dẫn cho trước

Em muốn tạo ra một workbook mới và tự động lưu vào đường dẫn cho trước thì phải làm như thế nào?
Thảo luận 1 câu trả lời
Lượt xem 473 lượt xem
Vỗ tay vỗ tay
Nguyễn Văn Khuyến 10:04 - Apr 11, 2020
Chào bạn bạn thực hiện theo code sau: chỉnh sửa phần Backup cho phù hợp nhé.
Option Explicit
Sub AutoBackup()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim xWs As Worksheet
Dim xWb As Workbook
Dim FSO As Object
Dim MyPath As String

Application.ThisWorkbook.Save
MyPath = ThisWorkbook.Path & "\Backup"'<< Duong dan thu muc Import

If Right(MyPath, 1) = "\" Then
MyPath = Left(MyPath, Len(MyPath) - 1)
End If

Set FSO = CreateObject("scripting.filesystemobject")

If FSO.FolderExists(MyPath) = FALSE Then
MsgBox "Duong dan " & MyPath & "Thu muc Backup duoc tao!", vbInformation
Dim FolderName As String
Application.ScreenUpdating = FALSE
Set xWb = Application.ThisWorkbook
FolderName = xWb.Path & "\" & "Backup" '& DateString
MkDir FolderName
MsgBox "File cua ban se duoc luu tai " & MyPath, vbInformation
ThisWorkbook.SaveCopyAs ThisWorkbook.Path & "\Backup\" & _
Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 5) & "(" & _
Right(Timer, 1) & ")" & Format(Date, "dd.mm.yyyy") & ".xlsm"
Else
MsgBox "File cua ban se duoc luu tai " & MyPath, vbInformation
ThisWorkbook.SaveCopyAs ThisWorkbook.Path & "\Backup\" & _
Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 5) & "(" & _
Right(Timer, 1) & ")" & Format(Date, "dd.mm.yyyy") & ".xlsm"
End If
Application.OnTime Now + TimeValue("00:00:20"), "AutoBackup"
End Sub
Vỗ tay vỗ tay
Câu hỏi liên quan
© 2020 - Bản quyền của Công Ty Cổ Phần Công Nghệ Giáo Dục Gitiho Việt Nam
Giấy chứng nhận Đăng ký doanh nghiệp số: 0109077145, cấp bởi Sở Kế hoạch và Đầu tư TP. Hà Nội
Giấy phép mạng xã hội số: 588, cấp bởi Bộ Thông tin và Truyền thông