Solved

Vbs to excel macro.

Posted on 2009-04-02
2
275 Views
Last Modified: 2012-05-06
Hi,

I have this vbs code that finds the Bios date of each machine in the txt file.
Now i want the same to work from within a excel file.
I have the machine names in colum "Q" instead of a txt file and want the results in colum "CW"

Regards
Sharath


on error resume next
 
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Set objReadFile = fso.OpenTextFile("C:\machines.txt", 1)
Set objWriteFile = FSO.OpenTextFile("C:\bios-dates.txt", 2, True)
 
objWriteFile.WriteLine """Computer"",""WMI Release Date"",""Release Date"""
 
do while not objReadFile.AtEndOfStream
    strComputer = objReadFile.ReadLine
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")
    For each objBIOS in colBIOS
        objWriteFile.WriteLine """" & strComputer & """,""" & objBIOS.ReleaseDate & """,""" & WMIDateStringToDate(Replace(objBIOS.ReleaseDate, "*", "0")) & """"
    Next
Loop
 
Set objFile = Nothing
Set fso = Nothing
 
 
Function WMIDateStringToDate(dtmInstallDate)
    WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) & " " & Mid (dtmInstallDate, 9, 2) & ":" & _
    Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, 13, 2))
End Function

Open in new window

0
Comment
Question by:bsharath
2 Comments
 
LVL 14

Accepted Solution

by:
rejoinder earned 500 total points
ID: 24057182
Can you try this please...
Sub Check_Computer_Hardware()
    on error resume next
    Application.EnableEvents = False
    
    For lngRow = 2 To Cells(65536, "Q").End(xlUp).Row
        strComputer = Trim(Cells(lngRow, "Q").Value)
        If strComputer <> "" Then
            Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
            Set colBIOS = objWMIService.ExecQuery ("Select * from Win32_BIOS")
    
            For each objBIOS in colBIOS
                dtmInstallDate = Replace(objBIOS.ReleaseDate, "*", "0")
                WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) & " " & Mid (dtmInstallDate, 9, 2) & ":" & Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, 13, 2))
                Cells(lngRow, "CW").Value = WMIDateStringToDate
            Next
        End If
    Next
    
    Application.EnableEvents = True
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 24058251
Thank U worked perfect...
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question