I'm having some problems converting VBA for Word 2000 to code that
VB.Net understands. I recorded a macro in Word to add numbering (a.
b. c.) to my paragraphs. I managed to translate quite a bit of it,
but I'm having trouble with two pieces:
ListGalleries - I can't find any way to make VB.Net understand this.
When I do a mouseover, the error message it gives is, "Interface
'Word.ListGalle ries' cannot be indexed because it has no default
property."
PointToInches - Not sure VB.Net even has a way to translate it.
Here is the Macro I recorded, followed by my transalted VB.Net code. I
removed some of the code I thought would be unnecessary to the
translation, but I could be wrong.
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 9/14/2004 by H2O
'
With ListGalleries(w dNumberGallery) .ListTemplates( 6).ListLevels(1 )
.NumberFormat = "%1."
.TrailingCharac ter = wdTrailingTab
.NumberStyle = wdListNumberSty leLowercaseLett er
.NumberPosition = InchesToPoints( 0.25)
.Alignment = wdListLevelAlig nLeft
.TextPosition = InchesToPoints( 0.5)
.TabPosition = InchesToPoints( 0.5)
.ResetOnHigher = 0
.StartAt = 1
With .Font
.Bold = wdUndefined
.Italic = wdUndefined
.StrikeThrough = wdUndefined
.Subscript = wdUndefined
.Superscript = wdUndefined
.Shadow = wdUndefined
.Outline = wdUndefined
.Emboss = wdUndefined
.Engrave = wdUndefined
.AllCaps = wdUndefined
.Hidden = wdUndefined
.Underline = wdUndefined
.Color = wdUndefined
.Size = wdUndefined
.Animation = wdUndefined
.DoubleStrikeTh rough = wdUndefined
.Name = ""
End With
.LinkedStyle = ""
End With
ListGalleries(w dNumberGallery) .ListTemplates( 6).Name = ""
Selection.Range .ListFormat.App lyListTemplate
ListTemplate:=L istGalleries( _
wdNumberGallery ).ListTemplates (6),
ContinuePreviou sList:=False, ApplyTo:= _
wdListApplyToWh oleList,
DefaultListBeha vior:=wdWord9Li stBehavior
Selection.TypeT ext Text:="Blah blah blah"
Selection.TypeP aragraph
Selection.TypeT ext Text:="Gah gah gah"
Selection.TypeP aragraph
Selection.TypeT ext Text:="Wee wee wee"
End Sub
------- Begin VB.Net Code -------
Private Sub testing(ByVal owordnew As Word.Applicatio n)
With owordnew
With .ListGalleries( Word.WdListGall eryType.wdNumbe rGallery).ListT emplates(6).Lis tLevels(1)
.NumberFormat = "%1."
.TrailingCharac ter =
Word.WdTrailing Character.wdTra ilingTab
.NumberStyle =
Word.WdListNumb erStyle.wdListN umberStyleLower caseLetter
.NumberPosition = InchesToPoints( 0.25)
.Alignment =
Word.WdListLeve lAlignment.wdLi stLevelAlignLef t
.TextPosition = InchesToPoints( 0.5)
.TabPosition = InchesToPoints( 0.5)
.ResetOnHigher = 0
.StartAt = 1
.LinkedStyle = ""
End With
.ListGalleries( Word.WdListGall eryType.wdNumbe rGallery).ListT emplates(6).Nam e
= ""
.Selection.Rang e.ListFormat.Ap plyListTemplate (ListTemplate:= ListGalleries(
_
Word.WdListGall eryType.wdNumbe rGallery).ListT emplates(6),
ContinuePreviou sList:=False, ApplyTo:= _
Word.WdListAppl yTo.wdListApply ToWholeList,
DefaultListBeha vior:=Word.WdDe faultListBehavi or.wdWord9ListB ehavior)
.Selection.Type Text(Text:="Bla h blah blah")
.Selection.Type Paragraph()
.Selection.Type Text(Text:="Gah gah gah")
.Selection.Type Paragraph()
.Selection.Type Text(Text:="Wee wee wee")
End With
End Sub
Thanks for any assistance,
MW
VB.Net understands. I recorded a macro in Word to add numbering (a.
b. c.) to my paragraphs. I managed to translate quite a bit of it,
but I'm having trouble with two pieces:
ListGalleries - I can't find any way to make VB.Net understand this.
When I do a mouseover, the error message it gives is, "Interface
'Word.ListGalle ries' cannot be indexed because it has no default
property."
PointToInches - Not sure VB.Net even has a way to translate it.
Here is the Macro I recorded, followed by my transalted VB.Net code. I
removed some of the code I thought would be unnecessary to the
translation, but I could be wrong.
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 9/14/2004 by H2O
'
With ListGalleries(w dNumberGallery) .ListTemplates( 6).ListLevels(1 )
.NumberFormat = "%1."
.TrailingCharac ter = wdTrailingTab
.NumberStyle = wdListNumberSty leLowercaseLett er
.NumberPosition = InchesToPoints( 0.25)
.Alignment = wdListLevelAlig nLeft
.TextPosition = InchesToPoints( 0.5)
.TabPosition = InchesToPoints( 0.5)
.ResetOnHigher = 0
.StartAt = 1
With .Font
.Bold = wdUndefined
.Italic = wdUndefined
.StrikeThrough = wdUndefined
.Subscript = wdUndefined
.Superscript = wdUndefined
.Shadow = wdUndefined
.Outline = wdUndefined
.Emboss = wdUndefined
.Engrave = wdUndefined
.AllCaps = wdUndefined
.Hidden = wdUndefined
.Underline = wdUndefined
.Color = wdUndefined
.Size = wdUndefined
.Animation = wdUndefined
.DoubleStrikeTh rough = wdUndefined
.Name = ""
End With
.LinkedStyle = ""
End With
ListGalleries(w dNumberGallery) .ListTemplates( 6).Name = ""
Selection.Range .ListFormat.App lyListTemplate
ListTemplate:=L istGalleries( _
wdNumberGallery ).ListTemplates (6),
ContinuePreviou sList:=False, ApplyTo:= _
wdListApplyToWh oleList,
DefaultListBeha vior:=wdWord9Li stBehavior
Selection.TypeT ext Text:="Blah blah blah"
Selection.TypeP aragraph
Selection.TypeT ext Text:="Gah gah gah"
Selection.TypeP aragraph
Selection.TypeT ext Text:="Wee wee wee"
End Sub
------- Begin VB.Net Code -------
Private Sub testing(ByVal owordnew As Word.Applicatio n)
With owordnew
With .ListGalleries( Word.WdListGall eryType.wdNumbe rGallery).ListT emplates(6).Lis tLevels(1)
.NumberFormat = "%1."
.TrailingCharac ter =
Word.WdTrailing Character.wdTra ilingTab
.NumberStyle =
Word.WdListNumb erStyle.wdListN umberStyleLower caseLetter
.NumberPosition = InchesToPoints( 0.25)
.Alignment =
Word.WdListLeve lAlignment.wdLi stLevelAlignLef t
.TextPosition = InchesToPoints( 0.5)
.TabPosition = InchesToPoints( 0.5)
.ResetOnHigher = 0
.StartAt = 1
.LinkedStyle = ""
End With
.ListGalleries( Word.WdListGall eryType.wdNumbe rGallery).ListT emplates(6).Nam e
= ""
.Selection.Rang e.ListFormat.Ap plyListTemplate (ListTemplate:= ListGalleries(
_
Word.WdListGall eryType.wdNumbe rGallery).ListT emplates(6),
ContinuePreviou sList:=False, ApplyTo:= _
Word.WdListAppl yTo.wdListApply ToWholeList,
DefaultListBeha vior:=Word.WdDe faultListBehavi or.wdWord9ListB ehavior)
.Selection.Type Text(Text:="Bla h blah blah")
.Selection.Type Paragraph()
.Selection.Type Text(Text:="Gah gah gah")
.Selection.Type Paragraph()
.Selection.Type Text(Text:="Wee wee wee")
End With
End Sub
Thanks for any assistance,
MW
Comment