Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Conditional Compilation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jkorchok@gmail.com - 14 Mar 2007 18:33 GMT
I am aware that there are no conditional compilation constants after
VBA6 to distinguish between versions of Word. I have also read items
like the following workarounds:

> What you can do is place all the office 2007-specific code into separate modules, If no code in that module is ever called when the template is used in Word 2003, then the template will run OK.

The problem I'm having is that either this doesn't work or I'm missing
something. I have a module called Word2003 that contains only the
following:

Sub TurnOffReading()
       Options.AllowReadingMode = False
End Sub

I call it like this:

If Left(Application.Version, 2) >= "11" And
Left(System.OperatingSystem, 3) = "Win" Then
   Word2003.TurnOffReading
End If

I still get the message "Compilation error in hidden module" when
running this in earlier versions of Word.
Jonathan West - 14 Mar 2007 20:43 GMT
>I am aware that there are no conditional compilation constants after
> VBA6 to distinguish between versions of Word. I have also read items
[quoted text clipped - 21 lines]
> I still get the message "Compilation error in hidden module" when
> running this in earlier versions of Word.

It looks like you may have neglected to put a line continuation character at
the end of the first line

You may want to investigate using the CallByName function to get round these
compile errors instead.

Have you tried running the code with the VBA editor open so you can see
which line causes the compile error?

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

jkorchok@gmail.com - 15 Mar 2007 17:22 GMT
Hi Jonathan,

If Left(Application.Version, 2) >= "11" And
Left(System.OperatingSystem, 3) = "Win" Then

is all on one line in the original code.

Options.AllowReadingMode = False

is the line that causes the compile error in version of Word earlier
than 2003.

Do you know of any source of information about CallByName? Most of
what I find by Googling refers to VB and the search engine seems to be
broken at the Word MVP site.

Thanks for any help!

John Korchok
Jonathan West - 16 Mar 2007 13:25 GMT
> Hi Jonathan,
>
[quoted text clipped - 7 lines]
> is the line that causes the compile error in version of Word earlier
> than 2003.

I suspect that the compile error is also happening somewhere else. Try
opening the template in Word 2000, opening the VBA editor, commenting out
that line and compiling the code. See which line the editor complains about.

> Do you know of any source of information about CallByName? Most of
> what I find by Googling refers to VB and the search engine seems to be
> broken at the Word MVP site.

Type CallByName into the immediate window in the VBA editor and press F1 to
bring up the Help topic on that keyword.

The CallByname version of that particular line is as follows

CallByName Options, "AllowReadingMode", VbLet, False

That won't cause a compile error. If you try to run that line in a version
of Word older than 2003, you will get a runtime error because the
AllowReadingMode property doesn't exist.

CallByName is slower than using the objects directly, but can be useful for
cases like this.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Scott Holmes - 16 Jul 2007 05:50 GMT
What you're doing works for me in VBA code that works with Word 97, 2000,
20002, 2003 and 2007, but with a couple of differences:

1. I use the Call statement. Example:
   Call Word2003.TurnOffReading
This probably makes absolutely no difference, but I include it for
completeness.

2. Running your code will not work with Word 97, which uses VBA5. To get
around this problem, I use conditional compilation to completely hide code
within each Sub in the hidden module. My suggestion for what to put inside
your module "Word2003":

**************************
'Subroutines that require Word 2003 or later.
' Calling anything in this module with an earlier version of Word will cause
an error.
' Conditional compilation allows compilation by Word 97.

'Following line makes this code public, but only within the project and
' not available using Word menu: Tools > Macro > Macros.
Option Private Module

Sub TurnOffReading()
   'Must hide the internal code from Word 97
   #If (VBA6) Then
       Options.AllowReadingMode = False
   #End If
End Sub

**************************

Good luck with MS Weird!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.