Word style problem

G

Guest

Hi,

I try to add/modify some style in Word 2002 and 2003 using VB, but I have
such error :
System.runtime.interopServces.COMException(0x800A1735) : Given Items does
not exist.
at word.Styles.get_item(Object& Index)

i don't have any number of code line where is the mistake..
i only know that my code is the following one :

wdApp = New Word.Application
wdDoc = wdApp.Documents.Add
'Word is hidden
wdApp.Visible = False

'Add 2 new styles to document
With wdDoc.Styles("Normal").Font
.Name = "Arial"
.Size = 10
.Bold = 0
.Italic = 0
.Underline = WdUnderline.wdUnderlineNone
.UnderlineColor = WdColor.wdColorAutomatic
.StrikeThrough = 0
.DoubleStrikeThrough = 0
.Outline = 0
.Emboss = 0
.Shadow = 0
.Hidden = 0
.SmallCaps = 0
.AllCaps = 0
.Color = WdColor.wdColorAutomatic
.Engrave = 0
.Superscript = 0
.Subscript = 0
.Scaling = 100
.Kerning = 0
.Animation = Word.WdAnimation.wdAnimationNone
End With

wdDoc.Styles.Add(Name:="DS SLA1",
Type:=Word.WdStyleType.wdStyleTypeParagraph)
wdDoc.Styles("DS SLA1").AutomaticallyUpdate = False
With wdDoc.Styles("DS SLA1").Font
.Name = "Arial"
.Size = 12
.Bold = 1
.Italic = 0
.Underline = WdUnderline.wdUnderlineNone
.UnderlineColor = WdColor.wdColorAutomatic
.StrikeThrough = 0
.DoubleStrikeThrough = 0
.Outline = 0
.Emboss = 0
.Shadow = 0
.Hidden = 0
.SmallCaps = 0
.AllCaps = 0
.Color = WdColor.wdColorAutomatic
.Engrave = 0
.Superscript = 0
.Subscript = 0
.Scaling = 100
.Kerning = 0
.Animation = Word.WdAnimation.wdAnimationNone
End With
With wdDoc.Styles("DS SLA1").ParagraphFormat
.LeftIndent = wdApp.CentimetersToPoints(0)
.RightIndent = wdApp.CentimetersToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = 0
.SpaceAfter = 0
.SpaceAfterAuto = 0
.LineSpacingRule = Word.WdLineSpacing.wdLineSpaceSingle
.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
'.WidowControl = CInt(1)
.KeepWithNext = 0
.KeepTogether = 0
.PageBreakBefore = 0
.NoLineNumber = 0
'.Hyphenation = 1
.FirstLineIndent = wdApp.CentimetersToPoints(0)
.OutlineLevel = Word.WdOutlineLevel.wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
wdDoc.Styles("DS SLA1").NoSpaceBetweenParagraphsOfSameStyle = False
wdDoc.Styles("DS SLA1").ParagraphFormat.TabStops.ClearAll()
With wdDoc.Styles("DS SLA1").ParagraphFormat
With .Shading
.Texture = Word.WdTextureIndex.wdTextureNone
.ForegroundPatternColor = Word.WdColor.wdColorAutomatic
.BackgroundPatternColor = Word.WdColor.wdColorAutomatic
End With
.Borders(Word.WdBorderType.wdBorderLeft).LineStyle =
Word.WdLineStyle.wdLineStyleNone
.Borders(Word.WdBorderType.wdBorderRight).LineStyle =
Word.WdLineStyle.wdLineStyleNone
.Borders(Word.WdBorderType.wdBorderTop).LineStyle =
Word.WdLineStyle.wdLineStyleNone
.Borders(Word.WdBorderType.wdBorderBottom).LineStyle =
Word.WdLineStyle.wdLineStyleNone
With .Borders
.DistanceFromTop = 1
.DistanceFromLeft = 4
.DistanceFromBottom = 1
.DistanceFromRight = 4
.Shadow = False
End With
End With
wdDoc.Styles("DS SLA1").LanguageID = Word.WdLanguageID.wdEnglishUS
wdDoc.Styles("DS SLA1").NoProofing = 0
wdDoc.Styles("DS SLA1").Frame.Delete()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top