473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Word 2000 macro -> VB.Net conversion question

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.ListGalleries' 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(wdNumberGallery).ListTemplates(6).Li stLevels(1)
.NumberFormat = "%1."
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleLowercaseLetter
.NumberPosition = InchesToPoints(0.25)
.Alignment = wdListLevelAlignLeft
.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
.DoubleStrikeThrough = wdUndefined
.Name = ""
End With
.LinkedStyle = ""
End With
ListGalleries(wdNumberGallery).ListTemplates(6).Na me = ""
Selection.Range.ListFormat.ApplyListTemplate
ListTemplate:=ListGalleries( _
wdNumberGallery).ListTemplates(6),
ContinuePreviousList:=False, ApplyTo:= _
wdListApplyToWholeList,
DefaultListBehavior:=wdWord9ListBehavior
Selection.TypeText Text:="Blah blah blah"
Selection.TypeParagraph
Selection.TypeText Text:="Gah gah gah"
Selection.TypeParagraph
Selection.TypeText Text:="Wee wee wee"
End Sub

------- Begin VB.Net Code -------

Private Sub testing(ByVal owordnew As Word.Application)

With owordnew
With .ListGalleries(Word.WdListGalleryType.wdNumberGall ery).ListTemplates(6).ListLevels(1)
.NumberFormat = "%1."
.TrailingCharacter =
Word.WdTrailingCharacter.wdTrailingTab
.NumberStyle =
Word.WdListNumberStyle.wdListNumberStyleLowercaseL etter
.NumberPosition = InchesToPoints(0.25)
.Alignment =
Word.WdListLevelAlignment.wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.5)
.TabPosition = InchesToPoints(0.5)
.ResetOnHigher = 0
.StartAt = 1
.LinkedStyle = ""
End With
.ListGalleries(Word.WdListGalleryType.wdNumberGall ery).ListTemplates(6).Name
= ""
.Selection.Range.ListFormat.ApplyListTemplate(List Template:=ListGalleries(
_
Word.WdListGalleryType.wdNumberGallery).ListTempla tes(6),
ContinuePreviousList:=False, ApplyTo:= _
Word.WdListApplyTo.wdListApplyToWholeList,
DefaultListBehavior:=Word.WdDefaultListBehavior.wd Word9ListBehavior)
.Selection.TypeText(Text:="Blah blah blah")
.Selection.TypeParagraph()
.Selection.TypeText(Text:="Gah gah gah")
.Selection.TypeParagraph()
.Selection.TypeText(Text:="Wee wee wee")
End With
End Sub
Thanks for any assistance,
MW
Nov 21 '05 #1
5 5313
Siv
I notice that you pass the Word application object byval, I would have
thought by reference would expose more stuff?

Does the Word object have to be passed at all, could you create it in the
same function as it is used?

Siv

"Mason" <ma*******@gmail.com> wrote in message
news:55**************************@posting.google.c om...
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.ListGalleries' 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(wdNumberGallery).ListTemplates(6).Li stLevels(1)
.NumberFormat = "%1."
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleLowercaseLetter
.NumberPosition = InchesToPoints(0.25)
.Alignment = wdListLevelAlignLeft
.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
.DoubleStrikeThrough = wdUndefined
.Name = ""
End With
.LinkedStyle = ""
End With
ListGalleries(wdNumberGallery).ListTemplates(6).Na me = ""
Selection.Range.ListFormat.ApplyListTemplate
ListTemplate:=ListGalleries( _
wdNumberGallery).ListTemplates(6),
ContinuePreviousList:=False, ApplyTo:= _
wdListApplyToWholeList,
DefaultListBehavior:=wdWord9ListBehavior
Selection.TypeText Text:="Blah blah blah"
Selection.TypeParagraph
Selection.TypeText Text:="Gah gah gah"
Selection.TypeParagraph
Selection.TypeText Text:="Wee wee wee"
End Sub

------- Begin VB.Net Code -------

Private Sub testing(ByVal owordnew As Word.Application)

With owordnew
With
.ListGalleries(Word.WdListGalleryType.wdNumberGall ery).ListTemplates(6).ListLevels(1)
.NumberFormat = "%1."
.TrailingCharacter =
Word.WdTrailingCharacter.wdTrailingTab
.NumberStyle =
Word.WdListNumberStyle.wdListNumberStyleLowercaseL etter
.NumberPosition = InchesToPoints(0.25)
.Alignment =
Word.WdListLevelAlignment.wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.5)
.TabPosition = InchesToPoints(0.5)
.ResetOnHigher = 0
.StartAt = 1
.LinkedStyle = ""
End With

.ListGalleries(Word.WdListGalleryType.wdNumberGall ery).ListTemplates(6).Name
= ""

.Selection.Range.ListFormat.ApplyListTemplate(List Template:=ListGalleries(
_
Word.WdListGalleryType.wdNumberGallery).ListTempla tes(6),
ContinuePreviousList:=False, ApplyTo:= _
Word.WdListApplyTo.wdListApplyToWholeList,
DefaultListBehavior:=Word.WdDefaultListBehavior.wd Word9ListBehavior)
.Selection.TypeText(Text:="Blah blah blah")
.Selection.TypeParagraph()
.Selection.TypeText(Text:="Gah gah gah")
.Selection.TypeParagraph()
.Selection.TypeText(Text:="Wee wee wee")
End With
End Sub
Thanks for any assistance,
MW

Nov 21 '05 #2
Yes, you're right, I should use byref. I had forgotten I'd changed it
when I was testing out ways to get it to work. I've tried creating the
document objects in the procedure, tried passing them, nothing seems to
work. VB even autocompletes while I'm typing the ListGalleries line in,
it just comes up with that error when I'm done entering it.

Are there any good resources out there for MS Word to VB.Net coding? A
book, or website, or something? I've been crawing along with what
Microsoft has for online help, but it isn't really comprehensive enough
for me.

Thanks again,

MW

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3
Siv
Mason,

I had a go at what you were trying to achieve as far as the renumbering bit is concerned. I have posted the application at http://www.sivill.com/Downloads/WordMacrosVBNet/ you can upload the various files and copy them to your machine and see if it works. What I have done is create a reference to the Word 10 object as that is what I have on my machine, you may need to change the reference on your machine to Office 9 to get it to work. I then create a variable that references the Word.application:

Inherits System.Windows.Forms.Form

Private Wd As Word.Application 'Reference the instance of Word which is added as a Project Reference.

Public Const wdParagraph As Word.WdUnits = 4 'Constant used by the Wd.Selection.MoveUp method - get by pressing F2 to get at the Word Objects and constants.

Public Const wdExtend As Word.WdMovementType = 1 'As above

The main routine that is called by pressing the button is as follows:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim MyNewDoc As Word.Document, n As Integer

Wd = New Word.Application

Wd.Visible = True

MyNewDoc = Wd.Documents.Add("Normal.dot", , , True)

For n = 1 To 5

Wd.Selection.TypeText("This is paragraph " & n & "." & vbCrLf)

Next n

Wd.Selection.MoveUp(Unit:=wdParagraph, Count:=5, Extend:=wdExtend)

Wd.Run("Temp") 'Runs a Macro called Temp in Normal.dot

If MessageBox.Show("OK All Done - Yes to exit and close Word Window, No to leave Word open!", "Word Macro Test App By Siv", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = DialogResult.Yes Then

MyNewDoc.Close(False) 'Don't save document (you probably would want to in your code).

Wd.Quit() 'Shutdown word

Wd = Nothing 'free up memory.

End If

End

'The following is what should be in your "Temp" macro this was in my Normal.dot

'With ListGalleries(wdNumberGallery).ListTemplates(5).Li stLevels(1)

' .NumberFormat = "%1)"

' .TrailingCharacter = wdTrailingTab

' .NumberStyle = wdListNumberStyleLowercaseLetter

' .NumberPosition = CentimetersToPoints(0.63)

' .Alignment = wdListLevelAlignLeft

' .TextPosition = CentimetersToPoints(1.27)

' .TabPosition = CentimetersToPoints(1.27)

' .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

' .DoubleStrikeThrough = wdUndefined

' .Name = ""

' End With

' .LinkedStyle = ""

'End With

'ListGalleries(wdNumberGallery).ListTemplates(5).N ame = ""

'Selection.Range.ListFormat.ApplyListTemplate(List Template:=ListGalleries( _

' wdNumberGallery).ListTemplates(5), ContinuePreviousList:=False, ApplyTo:= _

' wdListApplyToWholeList, DefaultListBehavior:=wdWord10ListBehavior)

'Selection.EndKey(Unit:=wdStory)



End Sub

The rem at the end of the sub is what I used as my "Temp" macro in Word in Normal.dot. If you are using a different template than "Normal.dot" you need to change the:

"MyNewDoc = Wd.Documents.Add("Normal.dot", , , True)"

bit so that your version references "xxyy.dot" or wahetever your's is called.

Needless to sat this code has no error trapping or anything!!

I hope this helps,

Siv


"Mason Wood" <ma***@codemonkey.cc> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Yes, you're right, I should use byref. I had forgotten I'd changed it
when I was testing out ways to get it to work. I've tried creating the
document objects in the procedure, tried passing them, nothing seems to
work. VB even autocompletes while I'm typing the ListGalleries line in,
it just comes up with that error when I'm done entering it.

Are there any good resources out there for MS Word to VB.Net coding? A
book, or website, or something? I've been crawing along with what
Microsoft has for online help, but it isn't really comprehensive enough
for me.

Thanks again,

MW

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #4
That worked beautifully, thanks a ton Siv. I didn't know how to make
VB.Net force Word to run a macro - knowing how is an enormous help.

I can't thank you enough,

MW

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #5
Siv
Glad it helped,
I'm sure next time you'll be able to help me when I get stuck.
Siv

"Mason Wood" <ma***@codemonkey.cc> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
That worked beautifully, thanks a ton Siv. I didn't know how to make
VB.Net force Word to run a macro - knowing how is an enormous help.

I can't thank you enough,

MW

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Poster | last post by:
After creating an IN clause from a bunch of character strings created by a Word macro, Query Analyzer complains about a syntax error. The macro takes a column full of character strings and wraps...
0
by: bekil | last post by:
Thanks for your suggestion Murray Jack. I also record macro while doing it manually in word then I edit the macro to see the required code. Firstly I am creating a blank page. Secondly I go to...
2
by: SSK | last post by:
hi i was trying to print a word document from a stored prcedure using the following two methods 1) cd C:\&&"C:\Program Files\Microsoft Office\OFFICE11\winword.exe" "c:\temp.doc" /mfileprint ...
2
by: Pete | last post by:
In Access 95/97 I used to be able to create pull down menus (File,Edit ...) from a macro. It seems there used to be some wizard for that. However in Access 2000 it seems you have to build your...
10
by: Brian Kwan | last post by:
Requirement: Call a Word Macro from ASP.NET with parameters Do anyone have idea about this? Please notice the import statement and sample code, as I am a beginner using ASP.NET, thanks for your...
1
by: Mat | last post by:
Hello everybody. i am having strange problem with Addin for word 2000. after each execution of a function or when user click on my button, a MESSAGE BOX from word application show stating that...
5
by: John | last post by:
Hi My vb.net opens a word document from a word template. I am trying to find when the document is saved by the user so I can make a history in my vb.net app. Here is how I think it may work; ...
3
by: Martin Austin | last post by:
Here's my problem. I'm launching an MS Word object on a Notes document Postopen event. The script kicks off a macro that saves the Word document to a temporary file every n minutes (backup of key...
1
by: Adam Faulkner via DotNetMonster.com | last post by:
I had a problem before extracting pages from an existing word document and then inserting the content into a new word document. The following code below works with Microsoft Word 2000 Function...
0
by: Curtiss | last post by:
I record a macro ok. Then when I run it delimiter screen pops up to select delimiter that was done when recording. Is it possible to get word to accept the delimiter selected when recording the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.