Conditionally Compile for Word 2007?

G

Gary Hillerson

Hi,

I've got a template that features in menu in earlier versions of Word,
and when it runs in Word 2007, I want it to use a tab on the ribbon
instead. I've got the tab working, and I know how to dynamically
determine (from Application.Version) if I'm running in Word 2007, so I
can make it work.

BUT: the module that works with the ribbon includes some declarations
(such as iRibbonControl) that are not available in earlier versions of
Word. So I don't think this code will work with earlier versions.

What's the best way to handle this? Is there a way to conditionally
compile the code? I know i can conditionally compile for a Macintosh
by including

#if Mac Then
'this code only included on mac versions
#Else
'this code only include on PC versions
#End If

but I don't know how to set up a condition like that "Mac" condition
that's built into VBA.


The only other way i can think to do this is to declare the
iRibbonControl parameters in my ribbon callbacks as variants. I assume
that would work, tho it makes the code a bit tougher to understand.

Any advice appreciated

thanks,
gary
 
J

Jean-Guy Marcil

Gary Hillerson was telling us:
Gary Hillerson nous racontait que :
Hi,

I've got a template that features in menu in earlier versions of Word,
and when it runs in Word 2007, I want it to use a tab on the ribbon
instead. I've got the tab working, and I know how to dynamically
determine (from Application.Version) if I'm running in Word 2007, so I
can make it work.

BUT: the module that works with the ribbon includes some declarations
(such as iRibbonControl) that are not available in earlier versions of
Word. So I don't think this code will work with earlier versions.

What's the best way to handle this? Is there a way to conditionally
compile the code? I know i can conditionally compile for a Macintosh
by including

#if Mac Then
'this code only included on mac versions
#Else
'this code only include on PC versions
#End If

but I don't know how to set up a condition like that "Mac" condition
that's built into VBA.


The only other way i can think to do this is to declare the
iRibbonControl parameters in my ribbon callbacks as variants. I assume
that would work, tho it makes the code a bit tougher to understand.

Any advice appreciated

I believe that if you use totally separate modules you should be OK.

When you call a sub, the compiler only compile the current module, not the
whole project.

So, if you have a central module that contains the version detection code,
which in turn call one of two modules depending on the detection result, it
should work.

Or, see this thread for another idea:
http://tinyurl.com/tekav


--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jay Freedman

Gary Hillerson was telling us:
Gary Hillerson nous racontait que :


I believe that if you use totally separate modules you should be OK.

When you call a sub, the compiler only compile the current module, not the
whole project.

So, if you have a central module that contains the version detection code,
which in turn call one of two modules depending on the detection result, it
should work.

Or, see this thread for another idea:
http://tinyurl.com/tekav

I concur. These techniques are the only ways I'm aware of to make the
same code compile in both old and new versions. They work, but they're
nowhere near as convenient as a compiler constant.

I talked to the leader of the Word programmability team in September
2005 about including a conditional compilation constant for Office
2007 like "Mac" and "VB6". For whatever reason, it wasn't implemented.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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