Check Folder Permissions Before Save VBA

后端 未结 2 1907
梦谈多话
梦谈多话 2021-01-23 02:16

I Have created a user form that will open an excel file open & hide the excel. When closing the user form will save & close the excel file. However, there are two types

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-23 02:30

    This checks the access list of the workbook's folder to see if the user's name appears in the list. If it does, then save the file.

    If Instr(1, Environ("USERNAME"), CreateObject("WScript.Shell").Exec("CMD /C ICACLS """ & _
    ThisWorkbook.Path & """").StdOut.ReadAll) > 0 Then ThisWorkbook.Save
    

    It does this by opening a command prompt, running the ICACLS command through it and reading the output from that command. Then it uses the InStr() method to see if the username appears in that output.

提交回复
热议问题