Previous in Forum: I Hate Google   Next in Forum: Favorite Defunct Software
Close
Close
Close
Rate Comments: Nested
Power-User

Join Date: Feb 2011
Location: Shimurali, Westbengal,India
Posts: 119

Processor Description Shows Error in VBA

05/07/2013 4:29 AM

I wrote a VBA program in excel 2007 (OS: windows XP SP1)

----------------------------------------------------------------

Option Explicit
Public ProcNum As String
Sub Worksheet_Open()
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
Dim WMI As Object, WQL As String, Proc As Object, Procs As Object, i As Integer
Sheets.Add
i = 1
Set WMI = GetObject("winmgmts:")
WQL = "select * from win32_processor"
Set Procs = WMI.ExecQuery(WQL)
For Each Proc In Procs
Cells(i, 1).Value = Proc.getObjectText_
i = i + 1
Next Proc
Set WMI = Nothing
Set Procs = Nothing
With Range("B1")
.FormulaR1C1 = "=CLEAN(MID(RC1,SEARCH(""{"",RC1)+1,SEARCH(""}"",RC1)-SEARCH(""{"",RC1)-1))"
.Value = .Value
End With
Range("B1").TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, Other:=True, OtherChar:=";", FieldInfo:=Array( _
Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), _
Array(13, 1), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), _
Array(19, 1), Array(20, 1), Array(21, 1), Array(22, 1), Array(23, 1), Array(24, 1), _
Array(25, 1), Array(26, 1), Array(27, 1), Array(28, 1), Array(29, 1), Array(30, 1), _
Array(31, 1), Array(32, 1), Array(33, 1))
Range("B1:AG1").Copy
Range("B2").PasteSpecial Paste:=xlPasteAll, Transpose:=True
Application.CutCopyMode = False
Columns(1).Delete
Rows(1).Delete
Columns(1).TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, Other:=True, OtherChar:="=", FieldInfo:=Array( _
Array(1, 1), Array(2, 1))
ProcNum = .Trim(.Substitute(Range("B21").Value, Chr(34), ""))
ActiveSheet.Delete
.EnableEvents = True
.DisplayAlerts = True
.ScreenUpdating = True
End With
MsgBox "Processor number is: " & ProcNum & vbCrLf & "Hard drive serial number is: " & DriveSerialNumber
End Sub

Function DriveSerialNumber() As String
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
DriveSerialNumber = Format(CDbl(FSO.Drives("C:").SerialNumber))

End Function
-----------------------

It shows an error 'AUTOMATION ERROR' when executing the line "For Each Proc In Procs".

Please help me.

Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Guru

Join Date: Mar 2007
Location: by the beach in Florida
Posts: 33392
Good Answers: 1817
#1

Re: Processor Description Shows Error in VBA

05/09/2013 2:44 AM
__________________
All living things seek to control their own destiny....this is the purpose of life
Register to Reply
Register to Reply

Previous in Forum: I Hate Google   Next in Forum: Favorite Defunct Software

Advertisement