Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Thu, 17 Jan 2008 01:47:23 GMT,    group: microsoft.public.word.vba.beginners        back       


6028 "The Range cannot be deleted"   
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)
-- 
Regards,

Christopher Kurtis Koeber
date: Thu, 17 Jan 2008 01:47:23 GMT   author:   Christopher Koeber

Re: 6028 "The Range cannot be deleted"   
You don't say where in the code the error is generated, but if I had to 
guess I would say it is

objDoc.Tables.Add objRange, NUMBER_OF_ROWS, NUMBER_OF_COLUMNS

at fault as the whole object document range probably includes the 
undeletable final para mark, which you may be implicitly attempting to 
delete by replacing it with the table...

You could try collapsing the objRange to the start first and see if that 
fixes it...

HTH

Julian
-- 
Julian I-Do-Stuff

Some Vista stuff, but mostly just Stuff at http://berossus,blogspot.com
"Christopher Koeber"  wrote in message 
news:Lsyjj.3332$8C1.2280@fe01.news.easynews.com...
> 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)
> -- 
> Regards,
>
> Christopher Kurtis Koeber
date: Thu, 17 Jan 2008 16:45:01 +0100   author:   Julian

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us