question

Starter0815 avatar image
0 Votes"
Starter0815 asked Viorel-1 answered

Serialnumbers from Monitors into a Excel-Sheet

Hallo,

with the Powershell-command:

 get-wmiobject wmimonitorid -namespace root\wmi|foreach-object{($_.SerialnumberID|foreach-object{[char]$_}) -join „“}

get the the serialnumbers from all attached Monitors back.

Is it possible to make this about VBA? My intention is to add the serialnumbers in to a separat cell in excel (per cell one serialnumber)?

Greetings

office-vba-devoffice-scripts-excel-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered

Check an example:

 Dim locator
 Set locator = CreateObject("WbemScripting.SWbemLocator")
    
 Dim service
 Set service = locator.ConnectServer(".", "root\wmi")
    
 Dim results
 Set results = service.ExecQuery("SELECT * FROM WmiMonitorId")
    
 Dim monitor
 For Each monitor In results
     Dim sn As String
     sn = ""
     For Each c In monitor.SerialNumberID
         sn = sn & Chr(c)
     Next
     MsgBox "Serial Number: " & sn
 Next

If it works, then replace the MsgBox line with cell operations.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.