[Hỏi] Tạo file trong ổ C bằng VBA không phải quyền Admin

Liên hệ QC

Mutants Men

Thành viên thường trực
Tham gia
30/12/15
Bài viết
394
Được thích
266
Mọi người cho em hỏi, em có code như thế này để tạo Folder và tạo file trong ổ C thì báo lỗi không thể tạo!
Vậy làm thế nào để có thể tạo được hay không? trường hợp đang đăng nhập với quyền User không phải Admin.
Em cảm ơn mọi người trước ạ.
Mã:
Sub Test()
    NewFolder "C:\NewFolder"
    WriteFile "C:\NewFolder\abc.txt", 123456
End Sub

Sub NewFolder(Optional ByVal path As String)
    On Error Resume Next
    If Len(path) = 0 Then Exit Sub
    Dim fso As Object:      Set fso = CreateObject("Scripting.FileSystemObject")
    If Not fso.FolderExists(path) Then fso.CreateFolder (path)
    Set fso = Nothing
    On Error GoTo 0
End Sub

Sub WriteFile(ByVal path As String, Optional ByVal Noidung As String)
    On Error Resume Next
    Dim TxtFile As Object
    Set TxtFile = fso.CreateTextFile(path, True, True)
    TxtFile.WriteLine Noidung
    TxtFile.Close
    Set fso = Nothing
    Set TxtFile = Nothing
    On Error GoTo 0
End Sub
 
Web KT
Back
Top Bottom