Excel's VBA <> Word's VBA?

S

Sonny Maou

I program using VBA for Word. I've imported some forms and code from a
Word project into Excel, but there are lots of issues. Is there a web
page I can go to to help distinguish the many differences between VBA
for Excel and VBA for Word?

Thanks.
 
C

Chip Pearson

Sonny,

The actual VBA used by Excel and Word is the same. The difference
lies in the object models of the Excel and Word applications.
Aside from books about Word and Excel programming, you can use
the Object Browser to see the object models.

Perhaps you could start by asking specific questions.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
S

Sonny Maou

Chip said:
Sonny,

The actual VBA used by Excel and Word is the same. The difference
lies in the object models of the Excel and Word applications.
Aside from books about Word and Excel programming, you can use
the Object Browser to see the object models.

Perhaps you could start by asking specific questions.

Thanks, Chip. I wanted to RTFM before I got into specific questions...
 
S

Sonny Maou

Chip said:
Perhaps you could start by asking specific questions.

Chip, the following code works in Word. Why doesn't it work in Excel? If
they are the "same VBA," why doesn't the constant wdUserTemplatesPath
work in Excel like it does in Word? How would the code below need to be
written to work in Excel?

Public Function dirPath(x)
Dim temp
If x = "user" Then
temp = Options.DefaultFilePath(wdUserTemplatesPath)
Else
temp = Options.DefaultFilePath(wdWorkgroupTemplatesPath)
End If
dirPath = temp
End Function

Thanks! :)
 
S

Sonny Maou

Joe said:
Hi Sonny,

First, the constants defined in the Word library are not defined in the Excel library and vice versa.

Well, that blows, since those same constants would seem to be shareable
at least within Office apps.
Second, Options.DefaultFilePath has no meaning in the Excel Object Model. What are you trying to do?

Firstly, I'm trying to get the "default file path" for user templates
and workgroup templates. Now that I look around Excel's Tools>Options
dialog box, I see that there is no place to specify these locations. :/

Ultimately, I'm trying to convert some document management code that has
been developed for Word documents into worksheet management code that
works in Excel... looks like it's going to be a long haul. :mad:

Thanks for your help! :)
 
E

Ed

Sonny: For the same reason a Ford key won't work in a Chevy. While the
engines both burn gas, the "keys" to make them run are different. So, too,
Excel and Word are different in what they do and how they do it, and the
commands needed to instruct the different programs to function. The prefix
"wd" is a dead giveaway that the instruction or parameter is specific to
Word.

Ed
 
S

Sonny Maou

Ed said:
Sonny: For the same reason a Ford key won't work in a Chevy.

Well, a Ford engine will work in a Chevy, with a little mod... maybe
that's a better analogy. or maybe not. :/
engines both burn gas, the "keys" to make them run are different. So, too,
Excel and Word are different in what they do and how they do it, and the
commands needed to instruct the different programs to function. The prefix
"wd" is a dead giveaway that the instruction or parameter is specific to
Word.

Yeah, I was hopin' for some real live compatibility between two
Microsoft Office apps. heh. Some may say I'm a dreamer... :)

Of course, I see the need for specific and necessarily incompatible
objects to represent each app's "docs"... I'm just bein' a whiner for a
moment. Thank you. :p
 
C

Chip Pearson

You can certainly automate on Office application from another.
They work together quite nicely in that respect. In VBA, go to
the Tools menu, choose References, and select the Microsoft Word
object library.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
D

Dave Peterson

For excel:

MsgBox Application.DefaultFilePath
MsgBox Application.NetworkTemplatesPath
MsgBox Application.TemplatesPath

And the only place I've seen where the Network templates path can be set by the
user is within word--but excel respects that setting.
 
S

Sonny Maou

Dave said:
For excel:

MsgBox Application.DefaultFilePath
MsgBox Application.NetworkTemplatesPath
MsgBox Application.TemplatesPath

And the only place I've seen where the Network templates path can be set by the
user is within word--but excel respects that setting.

Thank you, Dave... my first step toward cross-application compatibility! :)
 
Top