Once we are done with coding, save the file in macro enable excel format to avoid losing the code.If any value which we input is not an environment string table, then we will end up getting Zero-length string.We can get many more operating system details such as any path, location, folder or file, even any file size as well with the help of VBA Environ. The VBA Environ is not limited to the process shown in the above examples.We can also see who are the authorized user to use and edit the system.We can list out any specific detail as well as per our requirements.It gives the complete computer and operating system details.
It seems complex, but it is easy to implement.Step 12: We will see, in the immediate window, complete operating system details related to the functions which we have declared are fetched.
#How to debug vba in excel 2016 video code
Step 11: Now run the code by clicking on the Play button located below the menu bar. Step 10: Compile each step of the code and open an immediate window from the View menu tab. Step 9: Now use Debug Print for variable A and with Environ function as shown below. Step 8: Open a For-Next loop and give the length to variable A how long will be the character limit. Step 7: Define a variable as Long in which we will see the details. Step 6: After that open the subprocedure in which we will use both functions which we defined above to see their details. Step 5: Now again use any word which defines the Temp file path, like TempDir and insert Environ function with TEMP. Step 4: Let’s open another function by which we will see the temporary file path as shown below. Here we have chosen CompName and use Environ function with “ Computer Name”. Step 3: Suppose, if you want to see the Computer Name, use any word which defines Computer. Step 2: Now under Option Explicit, we will define the functions which we want to see.Ĭode: Option Explicit Function CompName() Step 1: Open a Module from the Insert menu tab. This works in the same manner as we have seen in example-1. For this, follow the below steps: There is another way by which we can get the complete information about the operating system which we have. This means that the user name which is mention at Sheet2 as Game2 is valid and authorized both. Once by the message box and other at cell E3. We will see, at C3, the authorized user name is printed as Game2 and then the same is confirmed twice. Step 14: Now we will run our macro by clicking on the command button named “Run Environ”. If all is good, then exit from the VBA window and unselect the Design mode from the Developer tab as shown below. Step 13: Now we will compile our code step by step by pressing the F8 function key to see if there is any error or not. Step 12: In Else give me the message as Unauthorized User as shown below. If Sheets("Sheet1").Range("E3") = "Yes" Then Step 11: Now open an IF-ELSE loop where write the condition if range cell E3 is YES then give me the message as Authorized User. Sheets("Sheet1").Range("C3") = Environ("USERNAME") Step 10: Now use Environ function with the field which we want to get. Step 9: Then select the range cells where we want to see the output. Step 8: Select the sheet where we want to apply the Environ function. Step 7: In that, we will get the pre-built sub procedure of the command button. Step 7: Now right-click on the same button and select View Code to go in the VBA window. Here we have chosen Run Environ as shown below.
Step 6: Under that, we can change the default name to anything. Step 5: Right-click on the created button and go to the Properties option. We can choose any Shapes over the command button as well. Step 4: Now create a command button anywhere in the sheet. Step 3: Now in excel worksheet, create a Command button that is available in the Developer tab under the Insert menu’s Active X Control as shown below. For both unauthorized and invalid user name, we will still get No. If the user name is valid and authorized then we will get YES, if valid but not authorized we will get No. Step 2: Under the header “ Authorized?” We will see if the user name is authorized or not with the If and CountIf function as shown below.