View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Excel Programming Question - VBA + WMI

Use the Change event

Right click on the sheet tab and select View Code (this brings up the Class
Module associated with that worksheet)

In the left dropdown, select Worksheet. In the Right Dropdown Select Change
(not selection change)

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

End Sub

Now you can built your code there

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.count 1 then exit sub
If Target.Column = 1 then
' apply validation, modified from
' macro recorder
cells(Target.Row,"B").Value = 21
cells(Target.Row,"C").Formula = "=rand()"
cells(Target.Row,"D").Formula = "=if(" & _
"A" & target.row & "5,""High"",""Low"")"
With Cells(Target.row,"H").Validation
.Delete
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, _
Formula1:="Yes,No"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With

' code to do other entries
End if
End Sub

------
For your vbscript, why not move the code to Excel and run it there -
particularly if you are returning result.. Alternately, look at the shell
command

--------

Dim sh as worksheet, sh1 as Worksheet
Dim i as Long
set sh1 = Worksheets("Data")
i = 1
for each sh in Worksheets
if sh.Name < "Data" then
sh1.Cells(i,"G").Value = sh.Name
i = i + 1
end if
Next

--
Regards,
Tom Ogilvy


"Jim Gregg" wrote in message
ups.com...
Hello all,

I am a fairly proficient vbscript programmer using WMI and ADSI, but
recently I have had to get involved with doing some programming in
Excel and I am a bit lost on a few things. Basically, I am looking for
a little help with the following things:

1. Is there any way to programmatically build a new row in excel when
someone adds a new value to a spreadsheet. For example, when someone
puts a computer name in A:2 (this being the next empty row), can I
somehow enter value in B2, C2, etc. I am specifically looking to add a
drop down list in H2 with the values Yes & No, with Yes being the
default. I also want to add sone specific values in cells in the same
row based on some instr() or instrRev() code that I want to run against
the value entered in B1.

2. Can I call a script that runs a WMI or ADSI query written in
vbscript from within excel? Again, this would probably be fired off of
values being entered in the first cell of the next empty row.

3. Finally, I have a series of worksheets (tabs) based on domain names.
How could I read the names of the tabs and output the names into a
range of cells? Example, tab 1 is mydomain and that would be in G1, tab
2 is mydomain2 and that would be in G2, etc.

I appreciate any assistance on this matter. Thank you all in advance.

Jim Gregg