xin code lưu file

Liên hệ QC

chickenexcel

Thành viên hoạt động
Tham gia
24/8/12
Bài viết
152
Được thích
28
Giới tính
Nam
Kính gửi anh/chị!
Em muốn nhờ giúp code lưu file theo 2 cách:
- 1. Lưu tại desktop
- 2. Lưu tại folder cùng file gốc. VD: file gốc nằm tại D:\Folder\ thì file save sẽ cùng thư mục đó (tên file sẽ là tên của file gốc + ô A1 sheet1.xlsx)
E thử dùng Macro để ghi sự kiện nhưng với cách 1 thì chỉ lưu được tại Desktop cá nhân (C:\Users\chickenexcel\Desktop). Vậy làm sao để người khác tự lưu tại destop của họ?
Em cảm ơn!
 
đổi qua lưu trong 1 forder trong ổ đĩa như ổ C hoặc ổ D là được . nhớ là mấy máy kia cũng phải có ổ đĩa giống vậy
 
Upvote 0
đổi qua lưu trong 1 forder trong ổ đĩa như ổ C hoặc ổ D là được . nhớ là mấy máy kia cũng phải có ổ đĩa giống vậy
Mỗi 1 acc là 1 đường dẫn ổ C khác nhau nên không lưu được chung bạn ạ. còn lưu tại ổ khác như ổ D cũng được nhưng mình muốn lưu theo hướng thuận tiện, ko mất công di chuyển nhiều. Trước có bài tương tự nhưng giờ tìm không thấy, không nhớ từ khóa để tìm :confused:
 
Upvote 0
bác nào giúp em với ạ!
 
Upvote 0
Kính gửi anh/chị!
Em muốn nhờ giúp code lưu file theo 2 cách:
- 1. Lưu tại desktop
- 2. Lưu tại folder cùng file gốc. VD: file gốc nằm tại D:\Folder\ thì file save sẽ cùng thư mục đó (tên file sẽ là tên của file gốc + ô A1 sheet1.xlsx)
E thử dùng Macro để ghi sự kiện nhưng với cách 1 thì chỉ lưu được tại Desktop cá nhân (C:\Users\chickenexcel\Desktop). Vậy làm sao để người khác tự lưu tại destop của họ?
Em cảm ơn!
Dùng thử code này.
Mã:
    MsgBox CreateObject("WScript.Shell").specialfolders("Desktop")
    MsgBox ThisWorkbook.Path
 
Upvote 0
Em làm được rồi.Em cảm ơn ạ!
còn ý này có thực hiện được không ạ?
thử cái này:
Mã:
With CreateObject("Scripting.FileSystemObject")
    strPath = .GetParentFolderName(strFullNameFileWithPath_Original) & "\"
    strBaseNameOriginalFile = .GetBaseName(strFullNameFileWithPath_Original)
    strExtensionOriginalFile = .GetExtensionName(strFullNameFileWithPath_Original)
    strFullNameFileWithPath_New = strPath & strBaseNameOriginalFile & "_" & strSheetName & "." & strExtensionOriginalFile
End With
 
Upvote 0
thử cái này:
Mã:
With CreateObject("Scripting.FileSystemObject")
    strPath = .GetParentFolderName(strFullNameFileWithPath_Original) & "\"
    strBaseNameOriginalFile = .GetBaseName(strFullNameFileWithPath_Original)
    strExtensionOriginalFile = .GetExtensionName(strFullNameFileWithPath_Original)
    strFullNameFileWithPath_New = strPath & strBaseNameOriginalFile & "_" & strSheetName & "." & strExtensionOriginalFile
End With
Thank bạn!
Chưa làm được, mình mò tiếp vậy
 
Upvote 0
Thank bạn!
Chưa làm được, mình mò tiếp vậy
mình viết cho bạn cái function tạo tên file với Path là trùng với cái path file cũ của bạn đó
Mã:
Function CreatFullNameFile (Byval strFullNameFileWithPath_Original as String, byval strSheetName as String) as String
Dim strPath as String,  strBaseNameOriginalFile as String, strExtensionOriginalFile as String
Dim strFullNameFileWithPath_New as String
With CreateObject("Scripting.FileSystemObject")
        strPath = .GetParentFolderName(strFullNameFileWithPath_Original) & "\"
        strBaseNameOriginalFile = .GetBaseName(strFullNameFileWithPath_Original)
        strExtensionOriginalFile = .GetExtensionName(strFullNameFileWithPath_Original)
        strFullNameFileWithPath_New = strPath & strBaseNameOriginalFile & "_" & strSheetName & "." & strExtensionOriginalFile
    End With
    CreatFullNameFile = strFullNameFileWithPath_New
End Function
 
Upvote 0
Web KT
Back
Top Bottom