Word macro to VB

J

Jezebel

VBA and VB are very similar; a lot of the time you need do nothing at all.
Intrinisic commands in Word VBA are actually methods of the Word application
object, so in some cases the conversion is largely along the lines --

Dim pWordApp as object

Set pWordApp = CreateObject("Word.Application")
with pWordApp
.Selection .....
.Bookmarks("MyBookmark").Range ...

etc
end With

However, there are some VBA things that do not work in VB. In particular,
forms are completely different and will have to be re-created.
 
J

Jonathan West

Hi Terry,

Perry's response is correct as far as VB6 is concerned. For VB.NET there may
be more changes you need to make, as there are rather more changes in the
syntax. For instance

- By default paramaters are passed by value rather than by reference
- Integer is now called Short, and Long is now called Integer
- You have to put parentheses round the list of arguments when you make a
subroutine call
 
P

Perry

Perry's response is correct as far as VB6
??

Y're sure you had some coffee before posting yr message, Jonathan?
:))

Perry

Jonathan West said:
Hi Terry,

Perry's response is correct as far as VB6 is concerned. For VB.NET there may
be more changes you need to make, as there are rather more changes in the
syntax. For instance

- By default paramaters are passed by value rather than by reference
- Integer is now called Short, and Long is now called Integer
- You have to put parentheses round the list of arguments when you make a
subroutine call

--
Regards
Jonathan West - Word MVP
http://www.multilinker.com
Please reply to the newsgroup
 
P

Perry

Talking about converting

You can't safely push a Word macro through a translator- or
converter utility/program to do the converting, if at all possible.

You'll have to code yr way through.
Next to the statements Jonathan contributed, let me
illustrate another feature you need to be aware of:

Where as in ole VB you would instantiate an Automation server
object listed in the MSOffice lib as follows:

Dim wdApp As New Word.Application
This wud go for all Office apps acting as Automation server, also in VBA.

In .NET however, although you can use the same syntax, there are a few
glitches:
You can't terminate a class instantiated as listed above (the old way),
unless you play around with the so called: Garbage Collector
or CType() the object back.

One of the remedies:
Dim wdApp As New Word.ApplicationClass

This is only one example in how .NET differs from the ole VB (...VBA)
syntax;
just wanted to illustrate things you need to be aware of ...

Are we already speaking about "ole VB" ... ??
:))

To come back to your question:
Yes, you can convert Word macro's to either VB or VB.net BUT ...

Krgrds,
Perry
 

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