C
Christopher Koeber
When I tried to run the code on Word 2007 in Vista below I get error
6028 "The Range cannot be deleted". The code works fine in Word 2003 on Win
XP. Any ideas?
Const NUMBER_OF_ROWS = 1
Const NUMBER_OF_COLUMNS = 3
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Set objRange = objDoc.Range()
objDoc.Tables.Add objRange, NUMBER_OF_ROWS, NUMBER_OF_COLUMNS
Set objTable = objDoc.Tables(1)
objTable.Cell(1, 1).Range.Text = "Service Name"
objTable.Cell(1, 2).Range.Text = "Display Name"
objTable.Cell(1, 3).Range.Text = "Service State"
x = 2
strComputer = "."
Set objWMIService = _
GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
For Each objItem in colItems
objTable.Rows.Add()
objTable.Cell(x, 1).Range.Text = objItem.Name
objTable.Cell(x, 2).Range.Text = objItem.DisplayName
objTable.Cell(x, 3).Range.Text = objItem.State
x = x + 1
Next
objTable.AutoFormat(9)
6028 "The Range cannot be deleted". The code works fine in Word 2003 on Win
XP. Any ideas?
Const NUMBER_OF_ROWS = 1
Const NUMBER_OF_COLUMNS = 3
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Set objRange = objDoc.Range()
objDoc.Tables.Add objRange, NUMBER_OF_ROWS, NUMBER_OF_COLUMNS
Set objTable = objDoc.Tables(1)
objTable.Cell(1, 1).Range.Text = "Service Name"
objTable.Cell(1, 2).Range.Text = "Display Name"
objTable.Cell(1, 3).Range.Text = "Service State"
x = 2
strComputer = "."
Set objWMIService = _
GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
For Each objItem in colItems
objTable.Rows.Add()
objTable.Cell(x, 1).Range.Text = objItem.Name
objTable.Cell(x, 2).Range.Text = objItem.DisplayName
objTable.Cell(x, 3).Range.Text = objItem.State
x = x + 1
Next
objTable.AutoFormat(9)