Hi,
Can these 2 macros be combined into one. 1. Is to get if machines are 64 or 32 bit 2. Get Mac address.
Code 1
Sub Get_64bit_32bit_Hardware()
Application.DisplayAlerts = False
Const wbemFlagReturnImmediately = &H10
Const wbemFlagForwardOnly = &H20
For intRow = 2 To Cells(65536, "Q").End(xlUp).Row
If Cells(intRow, "AC").Value = "" Then
strComputer = Cells(intRow, "Q").Value
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
If Err.Number = 0 Then
On Error GoTo 0
Set colItems = objWMIService.ExecQuery("S
ELECT AddressWidth FROM Win32_Processor", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
Cells(intRow, "AC").Value = objItem.AddressWidth & "-bit"
Next
End If
End If
Next
MsgBox "Done"
Application.DisplayAlerts = True
End Sub
Code 2
Sub Display_MAC_Address()
Application.DisplayAlerts = False
For intRow = 2 To Cells(65536, "Q").End(xlUp).Row
strComputer = Cells(intRow, "Q").Value
If Ping(strComputer) = True Then
strMACAddress = Get_MAC_Address(strCompute
r)
Cells(intRow, "AD").Value = strMACAddress
End If
Next
MsgBox "Finished."
Application.DisplayAlerts = True
End Sub
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel
l")
boolCode = objShell.Run("Ping -n 4 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
Function Get_MAC_Address(strCompute
r)
Set objShell = CreateObject("WScript.Shel
l")
Set objFSO = CreateObject("Scripting.Fi
leSystemOb
ject")
On Error Resume Next
objFSO.DeleteFile "D:\MAC.txt", True
On Error GoTo 0
objShell.Run "cmd /c NBTSTAT -a " & strComputer & " | FIND ""MAC Address"" > D:\MAC.txt", 0, True
Set objMACFile = objFSO.openTextFile("D:\MA
C.txt", 1, False)
While Not objMACFile.AtEndOfStream
strLine = objMACFile.ReadLine
If Len(strLine) > 35 Then
strMAC = Mid(strLine, 19, 17)
End If
Wend
objMACFile.Close
Set objMACFile = Nothing
Set objShell = Nothing
Set objFSO = Nothing
Get_MAC_Address = strMAC
End Function
These 2 macros work perfect in seperately.
As i have lots of macros need to combine some.
Is it possible that it checks the machine names in colum "Q" and query 1 machine on both the tasks and then come to the next.
Regards
Sharath
Start Free Trial