VBA & Macro Problems

Use VBA in WPS Office Spreadsheets to Associate a MAC Address with a Department

John WilsonJohn Wilson Nov 13, 2026 868 views

Question details

The user needs to identify a computer's MAC address through VBA in WPS Office and map it to a user or department, preferably using a maintainable worksheet lookup table.

Use VBA in WPS Office Spreadsheets to Associate a MAC Address with a Department
Product
WPS Office Spreadsheets (VBA/Macro)
Device & OS
Windows
Scenario
An administrator or analyst wants to run a VBA macro that reads the local network adapter address and returns the responsible department for reporting, device checks, or asset tasks.
Observed behavior
The macro should return the associated department from a mapping table rather than relying on hard-coded If statements.
Before you start

Enable the Developer tab in WPS Spreadsheets and save the workbook as a macro-enabled .xlsm file. Also create the worksheet columns that will hold the normalized MAC addresses and department names.

Solution 1Recommended

Retrieve the MAC Address with VBA and Look Up the Department from a Worksheet Table

Use this method when you want a maintainable mapping that avoids hard-coded If statements and is easy to update.

WMI's Win32_NetworkAdapterConfiguration class returns adapter MAC addresses. Normalizing the value with UCase and Trim before lookup prevents mismatches, and a named worksheet range is easier to maintain than editing VBA code.

1
Open the Visual Basic editor

In WPS Spreadsheets, click the Developer tab and select Visual Basic to open the VBA editor.

2
Insert a module

In the VBA editor, click Insert > Module to create a new code module.

3
Add the GetMAC function

Paste a VBA function that uses WMI to query Win32_NetworkAdapterConfiguration and returns the MAC address of the first active network adapter.

4
Create the department lookup table

In a worksheet, list normalized MAC addresses in one column and department names in the next column, then select the range and define the name DepartmentTable.

5
Write the lookup function

Add a function that applies UCase and Trim to the MAC value, then uses Application.VLookup to return the matching department from DepartmentTable.

6
Test the macro

Run the macro or enter the function in a cell to verify it returns the correct department for the current computer.

Retrieve the MAC Address with VBA and Look Up the Department from a Worksheet Table
Check the MAC format: If the function returns #N/A, check that the MAC address in the table uses the same uppercase, colon-separated format as the WMI result.
WPS Office VBA solution

Map MAC Addresses to Departments with a WPS Office VBA Macro

In WPS Office Spreadsheets, you can use the built-in VBA editor to query the local network adapter via WMI, normalize the MAC address, and return the department from a worksheet lookup table.

  1. 1. Enable the Developer tab: Open WPS Spreadsheets, go to File > Options > Customize Ribbon, and enable Developer to access the Visual Basic editor.
  2. 2. Insert a VBA module: Click Developer > Visual Basic, then Insert > Module to create a code module.
  3. 3. Add the MAC lookup function: Paste the VBA function that retrieves the MAC address through WMI and uses Application.VLookup to map it to a department.
  4. 4. Prepare the department lookup range: Enter MAC addresses and departments in a worksheet and define a named range such as DepartmentTable for the lookup.
  5. 5. Run and verify the macro: Use the function in a cell or run the macro to confirm the correct department is returned.
Uses a worksheet lookup table that is easier to update than hard-coded VBA conditions.Reads and writes Microsoft Excel .xlsm macro-enabled workbooks.Runs in the familiar WPS Office interface with VBA/WMI support on Windows.Free to download and lighter than traditional Office suites while keeping your VBA workflow.
microsoft office alternative - wps office

Frequently Asked Questions

Does WPS Office support VBA macros that use WMI?

Yes, on Windows WPS Office Spreadsheets can run VBA projects that use WMI through the standard VBA editor, subject to your local macro security settings.

Why should I use a worksheet lookup table instead of hard-coded If statements?

A table is easier to update and audit. You can change MAC-to-department mappings without editing code and use named ranges with Application.VLookup.

Can a single computer have multiple MAC addresses?

Yes. Laptops often have Ethernet, Wi-Fi, Bluetooth, and virtual adapters, so the macro should filter by adapter type or return all active MAC addresses before mapping.

Are MAC addresses a reliable way to identify users or departments?

Not for strict security. MAC addresses can be spoofed, changed, or hidden; for reliable identification prefer account-based authentication or device-management tools.

Does this macro work on macOS?

The WMI/getmac method is Windows-specific. On non-Windows systems, use a different command or a fixed mapping file.