There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Solved: VBS and Excel


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
Arkur55's Avatar
Junior Member with 5 posts.
 
Join Date: Dec 2005
Experience: Advanced
26-Dec-2005, 02:43 PM #1
Solved: VBS and Excel
This is what I need help with. Below is the section of code I am using:

objExcel.Cells(b, 14).Value = ((objDisk.DeviceID &" "& Round(objDisk.Size/1073741824) & "GB"))

This produces the drive ID and Size in the cell, However if the system has more than one drive the inormation is overwritten by the last drive found. For example:
Server1 is a 2003 server with Primary = C and Sercondary = D.
Server2 is a citrix server with Primary = M and Sercondary = N.

Server Name Drive C
Server1 D: 30GB
Server2 N: 19GB


What I need the code to do is insert a column into the spread sheet for each logical drive in the server. For example:

Server Name Drive 1 Drive 2 Drive 3
Server1 C: 24GB D: 324GB E: 324GB
Server2 M: 24GB N: 324GB E: 324GB


Can anyone help?
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 6,370 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
27-Dec-2005, 07:43 AM #2
You need some VBA code that has a "for/next" loop that uses the count of system drives.
Have you established how to find the number of drives in Excel?
Arkur55's Avatar
Junior Member with 5 posts.
 
Join Date: Dec 2005
Experience: Advanced
27-Dec-2005, 11:39 AM #3
Thanks OBP, What I can not figure out how to set the LogicalDisk to a variable and have the script loop through each existing drive and insert the information into an excel spread sheet. The way I am currently performing the task is with the script below. This would be great if all the servers had jus a C and D drive, but thats not the case.

What I am looking for is to have the script look for the drives like C: inset a column Labled Drive C at cell A1 and the Size in Cell A2 when it finds let say drive D: it inserts a colum
at cell B1 and the Size at B2.

Can you still help??


set oSvc = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
wqlQuery = "select DeviceID,Size from Win32_LogicalDisk where Name = 'C:'"

For Each oData In oSvc.ExecQuery(wqlQuery)
for each oProperty in oData.Properties_
if oProperty.Name = "DeviceID" Then
DiskName = oProperty.Value
elseif oProperty.Name = "Size" Then
DiskSize = oProperty.Value
end If
Next
WScript.Echo (DiskName & vbTab & DiskSize)
objExcel.Cells(b, 14).Value = ((DiskName &" "& Round(DiskSize/1073741824) & " GB"))
Next
wqlQuery = "select DeviceID,Size from Win32_LogicalDisk where Name = 'D:'"

For Each oData In oSvc.ExecQuery(wqlQuery)
for each oProperty in oData.Properties_
if oProperty.Name = "DeviceID" Then
DiskName = oProperty.Value
Elseif oProperty.Name = "Size" Then
DiskSize = oProperty.Value
end If
Next
WScript.Echo (DiskName & vbTab & DiskSize)
objExcel.Cells(b, 15).Value = ((DiskName &" "& Round(DiskSize/1073741824) & " GB"))
next

Last edited by Arkur55 : 27-Dec-2005 12:12 PM.
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 6,370 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
27-Dec-2005, 01:36 PM #4
I do not know if I can help, but I know a man who probably can, Zack the Firefytr, I will send him an email. I can do it with VBA from within Excel, but not with VBS.
Arkur55's Avatar
Junior Member with 5 posts.
 
Join Date: Dec 2005
Experience: Advanced
27-Dec-2005, 02:04 PM #5
OBP,

I had some additional help and came up with the following code.
So if you are ever asked the same question below is the answer.

Thanks for your assistance and replys.

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""

Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")
ColOffset = 0
For Each objDisk in colDisks
objExcel.Cells(b, 14 + ColOffset).Value = ((objDisk.DeviceID &" "& Round(objDisk.Size/1073741824) & " GB"))

ColOffset = ColOffset + 1

Next
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 6,370 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
27-Dec-2005, 02:19 PM #6
Arkur, thanks for the info. Can you mark your thread as "Solved" using the thread tools at the top of the page please?
Arkur55's Avatar
Junior Member with 5 posts.
 
Join Date: Dec 2005
Experience: Advanced
27-Dec-2005, 02:22 PM #7
Yes, Thanks!
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 06:02 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.