+ Reply to Thread
Results 1 to 2 of 2

Run Command Prompt Icacls code in VBA Command Button on Userform

  1. #1
    Registered User
    Join Date
    06-04-2014
    Posts
    7

    Run Command Prompt Icacls code in VBA Command Button on Userform

    Hi,

    The following code runs perfect in Command Prompt - Icacls "\\server\Users_Data\Tim" /grant "Tim"OI)(CI)M

    The above code adds the user "Tim" to the Folder "Tim" by the same name and it sets the permission to Modify successfully with Command Prompt. I would like to do this same thing in a command button in a Excel Userform.
    When I write the code in the Command Button in a Excel Userform, it turned RED alert "Compile Error".

    I have been looking into how to run this from the Userform and basically every post says the same, "Need to Use Shell". I do not know how to code this to run in a Shell.

    Could someone assist on how run this from a CommandButton in a Userform.


    Regards,

  2. #2
    Registered User
    Join Date
    06-04-2014
    Posts
    7

    Re: Run Command Prompt Icacls code in VBA Command Button on Userform

    I figured it out after modifying the code found here:

    http://www.developerteacher.com/msdn...servers-466371

    1. This code will create a Home Folder on the file server with the users name.
    2. This code will add the user to the Home Folder as he/she will only have access to it.
    3. This code will add the Modify Permission for the user on the Folder.

    To run the code in a Command Button on a UserForm in Excel this would be the coding:

    ----------------------------------------------------------------------------------------------------------------

    Private Sub CommandButton1_Click()

    Dim UserName As String 'Declares the variables to hold the value entered in the textbox
    Dim strHomeFolder 'variable to hold the path to the share folder
    Dim objShell 'variable tp holds the creation og object wscript.shell

    'Sets the variable to the value of the textbox
    UserName = TextBox1.Text

    'Creates the Home folder with the users Name as entered in the textbox
    MkDir "\\Server\Share_Folder\" & UserName

    'sets the path to the variable strHomeFolder
    strHomeFolder = "\\Server\Share_Folder\" & UserName

    'sets the("Wscript.Shell") to the variable objShell
    Set objShell = CreateObject("Wscript.Shell")

    ' Assign modify permission to home folder created above with users name
    Run objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder & " /e /c /g " & UserName & ":c ")

    End Sub

    ----------------------------------------------------------------------------------------------------------------

    I hope this helps someone else.

    Regards,
    Last edited by luismalave; 08-19-2015 at 11:42 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Not sure how to write the code for the command button when making a userform
    By andzia in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-12-2015, 05:45 PM
  2. Userform VBA command button code required or explained
    By lcartwright in forum Excel General
    Replies: 0
    Last Post: 02-03-2015, 06:17 PM
  3. [SOLVED] Userform: Code for DELETE on a command button
    By Gal403 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-25-2014, 01:28 AM
  4. [SOLVED] VBA Code to Gray Out Command Button on Userform
    By riffology in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2013, 02:49 PM
  5. [SOLVED] getting data from command button in userform why is my code not working?
    By Curious2 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 06-07-2013, 10:37 AM
  6. [SOLVED] Excel vba userform - code for command button not working
    By PANTECH in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-26-2013, 11:27 AM
  7. Code for a master command button to change the backcolor of multiple command buttons?
    By panttherm5 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2012, 10:11 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1