+ Reply to Thread
Results 1 to 8 of 8

Marco to get Windows sessions + machine

  1. #1
    Forum Contributor
    Join Date
    02-21-2007
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    389

    Marco to get Windows sessions + machine

    Hello,

    I am using a excel file to gather information from IT guys. Instead of requesting to enter their username and hostname, I was wondering if I could use a macro that would get the windows session and the windows username (cmd > hostname).

    FYI. I already use a macro to record information.

    If you need further infor please let me know. I use excel 2010

    Graig

  2. #2
    Forum Contributor
    Join Date
    02-21-2007
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    389

    Re: Marco to get Windows sessions + machine

    I have seen this article that would pretty much match what I need.. But I need the username and hostname copied in the A2 and B2 cells..

    Here is the macro:

    HTML Code: 
    I did not get how that macro should be used.. Any help would be more than welcome

  3. #3
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Marco to get Windows sessions + machine

    I am wondering-as you didn't feed back - if your problem in this thread was solved!
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: Marco to get Windows sessions + machine

    Please Login or Register  to view this content.
    Add the lines in Red to your code and install as below

    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Forum Contributor
    Join Date
    02-21-2007
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    389

    Re: Marco to get Windows sessions + machine

    @ Fotis1991: I've just provided my feedback.
    @ alansidman: Thank you. I do know how to run the macro but I do not know how to manage to have the username in B1 cell and hostname in the B2 cell.

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: Marco to get Windows sessions + machine

    graiggoriz;
    BTW the dollar sign ($) after the Environ is extraneous as you have already declared sUserName and sHostName as Strings.

  7. #7
    Forum Contributor
    Join Date
    02-21-2007
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    389

    Re: Marco to get Windows sessions + machine

    I really do not get how that macro work! I did remove the $ before Environ..

    My goal is to get the username in B1 and hostname in B2

    I attache the file in case I miss a step (at least to run macro I found which will not give m e exactly what I wish).

    Thanks,
    Graig
    Attached Files Attached Files

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: Marco to get Windows sessions + machine

    I checked your code. You did not add in the lines of code that I highlighted in RED in post #4. This will add the items as you requested.

+ 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. Replies: 1
    Last Post: 02-06-2013, 06:13 PM
  2. Working code on my machine is returning out of range error on another machine.
    By je.suis.ketan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-16-2012, 11:51 PM
  3. Replies: 2
    Last Post: 03-01-2006, 12:25 AM
  4. Replies: 6
    Last Post: 02-28-2006, 01:20 AM
  5. Open Excel files in separate sessions, not just separate windows?
    By Bob at Dexia Design in forum Excel General
    Replies: 1
    Last Post: 10-18-2005, 01:05 PM

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