+ Reply to Thread
Results 1 to 6 of 6

Copy PC MAC address to worksheet: how to get rid of MsgBox?

  1. #1
    Registered User
    Join Date
    06-29-2006
    Posts
    16

    Copy PC MAC address to worksheet: how to get rid of MsgBox?

    Hi,

    I want to read a PC's MAC address and copy it to a worksheet. I have a code that works (see attached). I work on WindowsXP with Excel2002.

    The problem is that I had to put a MsgBox on line 19. If I remove the MsgBox command the sh.Exec on line 4 seems to be executed too slowly before opening MAC.txt on line 21. The code is executed but Sheet1 remains empty. That is why I put the MsgBox break.

    Does anyone know an elegant way to get rid of this MsgBox? I do not want to bother a user every single time with the MsgBox.

    I have tried pause commands or loops which check the existence of the MAC.txt file, but without success.

    If someone knows a better way to identify the MAC address alone, i.e. without the "Physical....", this would be even better

    Help appreciated.

    g
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Gstremer,

    I needed to do the same thing a few years back. Here is macro using API code to retrieve the Mac address. Add a standard module to your workbook and then copy and paste the macro code into it. This code obviates the need to store the address in a file, open it, etc. The macro funtion returns a formatted string containing the MAC address for the NIC. Your routine would become this...

    Please Login or Register  to view this content.
    Macro Code:
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    06-29-2006
    Posts
    16

    Great!

    Leith Ross,

    Thanks! Works great. Two comments:
    - I had to replace H33, H8, H4, H32 by &H33, &H8, &H4, &H32 for my configuration
    - Does this tool always take the ethernet card address, i.e. wireless card is neglected?

    Thanks again,

    g

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Gstremer,

    Sorry by the "H". I forgot than when I used the code last I had the same problem. Thought I had saved the corrections. Won't happen again.

    The code retrieves whatever the MAC for your default NIC card is. As long as the card is IEEE 802 compliant, it shouldn't matter if it is ethernet or wireless.

    Sincerely,
    Leith Ross

  5. #5
    Registered User
    Join Date
    06-29-2006
    Posts
    16
    Leith Ross,

    Thanks.

    Unfortunately I found out that your macro does not return the MAC address of the ethernet card when the network cable is unplugged. Also even when the wireless network is connected the corresponding MAC address is not returned. Any idea?

    Best regards,

    g

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Gstremer,

    I'll have to do a little research on your questions. I don't know that I will be able to answer your question today, but I will post what I find out.

    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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