Word VBA vs Excel VBA 
Author Message
 Word VBA vs Excel VBA

Hi everyone,

I am fairly new to VBA and was wondering how different the
two versions of VBA are. I learnt Excel VBA by recording a
few macros and learning from that; to the point where I
could write my own code.

I had a quick look at Word VBA and the amount of code that
it generates for some simple actions seems quite daunting.
Also, without cell reference, how does one navigate around
the page?

I am almost considering putting 'Learning Word VBA' into
the too hard basket.

I'm just seeking some comments on how hard/easy it is to
learn Word VBA and how much of the stuff that I have
learnt from Excel VBA can be transferred across onto this
platform.

Feel free to contact me via my email.

Henry.



Tue, 26 Oct 2004 13:50:45 GMT  
 Word VBA vs Excel VBA
The core of VBA is just about the same for Excel and Word.
They differ in the VBA specific to each of their object models, but even so,
a great deal of that is the same, or very similar.

If you already know Excel VBA, then pick up as copy of Steve Roman's Writing
Word Macros. I mention an earlier edition of that book in the list of Word
VBA books at my web site (URL below).

Also see my warnings about recorded macros in Word.

--
Please post your response to the newsgroup. Do not email me a copy of the
message.

http://www.standards.com/; Programming and support for  Word macros,
including converting from WordBasic to VBA; Technical reviewing; Standards;
Product functional/design/specifications
------------------------------------------------

Quote:
> Hi everyone,

> I am fairly new to VBA and was wondering how different the
> two versions of VBA are. I learnt Excel VBA by recording a
> few macros and learning from that; to the point where I
> could write my own code.

> I had a quick look at Word VBA and the amount of code that
> it generates for some simple actions seems quite daunting.
> Also, without cell reference, how does one navigate around
> the page?

> I am almost considering putting 'Learning Word VBA' into
> the too hard basket.

> I'm just seeking some comments on how hard/easy it is to
> learn Word VBA and how much of the stuff that I have
> learnt from Excel VBA can be transferred across onto this
> platform.

> Feel free to contact me via my email.

> Henry.



Tue, 26 Oct 2004 14:23:49 GMT  
 Word VBA vs Excel VBA
Hi Henry

For what it's worth, I learned along the same path as you. I started VBA
life in Excel and later MS Project, learned by recording and reading and
then doing stuff manually.

I've only come to Word macros recently. The object model frustrated me
completely at first, but I'm getting the hang of it. Some of it is
screamingly obvious: ActiveDocument.Paragraphs(3) is the third paragraph of
the current document. Some of it isn't. But then that applies to Excel
too<g>.

For the work I've done (which isn't especially complicated, I'll admit) it's
certainly no harder than Excel to learn. And the familiarity of the VBE and
basic commands (If/Then, For each, loops etc) is comforting.

Read the page at
http://www.mvps.org/word/FAQs/MacrosVBA/VBABasicsIn15Mins.htm. It's enough
to make you think "Yep! I can do this."

Don't give up yet!

Anne
Melbourne, Australia


Quote:
> Hi everyone,

> I am fairly new to VBA and was wondering how different the
> two versions of VBA are. I learnt Excel VBA by recording a
> few macros and learning from that; to the point where I
> could write my own code.

> I had a quick look at Word VBA and the amount of code that
> it generates for some simple actions seems quite daunting.
> Also, without cell reference, how does one navigate around
> the page?

> I am almost considering putting 'Learning Word VBA' into
> the too hard basket.

> I'm just seeking some comments on how hard/easy it is to
> learn Word VBA and how much of the stuff that I have
> learnt from Excel VBA can be transferred across onto this
> platform.

> Feel free to contact me via my email.

> Henry.



Wed, 27 Oct 2004 18:05:16 GMT  
 Word VBA vs Excel VBA
Hi, Henry,

Since Howard and Anne have given you reassurances, I'll just throw in answers to
a couple of your specific questions.

First, let's talk about the amount of code you get from the recorder versus the
amount of code you actually need to get something done in Word VBA. There's a
huge difference, especially when you record one of Word's built-in dialogs. For
instance, record the Replace dialog, and you'll get a mess like this:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 5/11/2002 by Jay Freedman
'
   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
      .Text = "find me"
      .Replacement.Text = "found it"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
End Sub

This lists every setting in the entire dialog, whether or not you changed it.
No, you don't need all of that! Probably all you really need is this:

Sub Macro2()
   With Selection.Find
      .Text = "find me"
      .Replacement.Text = "found it"
      .Execute Replace:=wdReplaceAll
   End With
End Sub

(Now the small print: The settings in the Find and Replace dialogs are
"sticky" -- they keep their values from one execution to the next -- so if you
change one of the settings in a manual Replace and then run the macro, that
setting will still be in effect. The first Find or Replace in each macro should
change all of the settings to a known condition.)

The other dialogs show similar behavior when you record them. Just open up the
Help topic for the command (such as Find.Execute), read the list of parameters,
and omit the optional ones unless you need them for something specific.

The question about "navigating around the page" is a little tougher to answer.
Many times you don't have to "navigate" at all. You can use the Find method to
go directly to some text of interest (and remember that you can find styles or
formatting as well as words, and you can use "wildcard searching"). You can
change formatting by applying or changing styles. You can work with bookmarks,
fields, or other objects that are already in the text, usually because they were
in the document's template. If you need to process every character, word,
paragraph, or section in the document, you can use the For Each ... Next
construct (although this gets terribly slow when you have to look at each
character or word).

Browse through the articles on the Macros/VBA tab at
http://www.mvps.org/word/FAQs/index.html to get a sense of what's available, and
then post questions here. We're happy to help!

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word


Quote:
> Hi everyone,

> I am fairly new to VBA and was wondering how different the
> two versions of VBA are. I learnt Excel VBA by recording a
> few macros and learning from that; to the point where I
> could write my own code.

> I had a quick look at Word VBA and the amount of code that
> it generates for some simple actions seems quite daunting.
> Also, without cell reference, how does one navigate around
> the page?

> I am almost considering putting 'Learning Word VBA' into
> the too hard basket.

> I'm just seeking some comments on how hard/easy it is to
> learn Word VBA and how much of the stuff that I have
> learnt from Excel VBA can be transferred across onto this
> platform.

> Feel free to contact me via my email.

> Henry.



Thu, 28 Oct 2004 08:46:45 GMT  
 Word VBA vs Excel VBA
See my rants at my URL below on the shortcomings of recording macros.

IMHO, lots of beginning Word VBA programmers get frustrated by recorded
macros not giving them what they expect.
MSFT should do a better job of describing the benefits and shortcomings of
using recorded macros.

--
http://www.standards.com/; Programming and support for  Word macros,
including converting from WordBasic to VBA; Technical reviewing; Standards;
Product functional/design/specifications
------------------------------------------------

Quote:
> Hi, Henry,

> Since Howard and Anne have given you reassurances, I'll just throw in
answers to
> a couple of your specific questions.

> First, let's talk about the amount of code you get from the recorder
versus the
> amount of code you actually need to get something done in Word VBA.
There's a
> huge difference, especially when you record one of Word's built-in
dialogs. For
> instance, record the Replace dialog, and you'll get a mess like this:

> Sub Macro1()
> '
> ' Macro1 Macro
> ' Macro recorded 5/11/2002 by Jay Freedman
> '
>    Selection.Find.ClearFormatting
>    Selection.Find.Replacement.ClearFormatting
>    With Selection.Find
>       .Text = "find me"
>       .Replacement.Text = "found it"
>       .Forward = True
>       .Wrap = wdFindContinue
>       .Format = False
>       .MatchCase = False
>       .MatchWholeWord = False
>       .MatchWildcards = False
>       .MatchSoundsLike = False
>       .MatchAllWordForms = False
>    End With
>    Selection.Find.Execute Replace:=wdReplaceAll
> End Sub

> This lists every setting in the entire dialog, whether or not you changed
it.
> No, you don't need all of that! Probably all you really need is this:

> Sub Macro2()
>    With Selection.Find
>       .Text = "find me"
>       .Replacement.Text = "found it"
>       .Execute Replace:=wdReplaceAll
>    End With
> End Sub

> (Now the small print: The settings in the Find and Replace dialogs are
> "sticky" -- they keep their values from one execution to the next -- so if
you
> change one of the settings in a manual Replace and then run the macro,
that
> setting will still be in effect. The first Find or Replace in each macro
should
> change all of the settings to a known condition.)

> The other dialogs show similar behavior when you record them. Just open up
the
> Help topic for the command (such as Find.Execute), read the list of
parameters,
> and omit the optional ones unless you need them for something specific.

> The question about "navigating around the page" is a little tougher to
answer.
> Many times you don't have to "navigate" at all. You can use the Find
method to
> go directly to some text of interest (and remember that you can find
styles or
> formatting as well as words, and you can use "wildcard searching"). You
can
> change formatting by applying or changing styles. You can work with
bookmarks,
> fields, or other objects that are already in the text, usually because
they were
> in the document's template. If you need to process every character, word,
> paragraph, or section in the document, you can use the For Each ... Next
> construct (although this gets terribly slow when you have to look at each
> character or word).

> Browse through the articles on the Macros/VBA tab at
> http://www.mvps.org/word/FAQs/index.html to get a sense of what's
available, and
> then post questions here. We're happy to help!

> --
> Regards,
> Jay Freedman
> Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word



> > Hi everyone,

> > I am fairly new to VBA and was wondering how different the
> > two versions of VBA are. I learnt Excel VBA by recording a
> > few macros and learning from that; to the point where I
> > could write my own code.

> > I had a quick look at Word VBA and the amount of code that
> > it generates for some simple actions seems quite daunting.
> > Also, without cell reference, how does one navigate around
> > the page?

> > I am almost considering putting 'Learning Word VBA' into
> > the too hard basket.

> > I'm just seeking some comments on how hard/easy it is to
> > learn Word VBA and how much of the stuff that I have
> > learnt from Excel VBA can be transferred across onto this
> > platform.

> > Feel free to contact me via my email.

> > Henry.



Thu, 28 Oct 2004 15:30:20 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Excel 97 VBA vs Excel 2000 VBA

2. vba access vs vba excel (alguien sabe?)

3. Call Excel VBA from Word VBA?

4. VBA code in Excel 97 vs Excel 2002

5. Windows EXCEL VBA / MAC EXCEL VBA compatibility issues

6. Access97 vba VS Access2000 vba

7. VBA 5 vs VBA 4

8. Interpretive VBA vs. Compiled VBA extensions to Project

9. Proj 98 VBA vs Proj 2000 VBA

10. VBA 97 vs VBA 2000

11. Word2000 VBA vs. Word97 VBA

12. Access VBA vs Excel 5.0

 

 
Powered by phpBB® Forum Software