"Compile Eror in hidden module"

S

Simon

Hi, I'm trying to fix ths error in my Word macros. Its happeing because I'm
using an Office 2003 property that isn't supported on Office XP:-
ActiveWindow.View.ShadeEditableRanges = False
Is there any way I can prevent Office XP and earlier versions from
attempting to compile the code they don't support?

Maybe there is a better way of doing what I'm trying to achieve... I need to
protect an image (company logo) in a word template from being deleted so I
have followed advice from this forum and protected the document then added an
exception range, editable by everyone so that only the logo is protected.
Now, by default Word highlights the editable areas which causes the document
to appear broken since it's made up of text in tables with background colors.
So I came up with the above VBA code to turn the highlighting off (its in the
code that creates the new document from the template and in Document_Open()).

I realize that the protection isn't effective in Office versions before 2003
but that is a minority of users and diminishing daily. I just need to protect
the image for the vast majority of users and have the macros work for
everyone. I can't be as difficult as I'm making it, surely??!!

Thanks for making it to the end of this long post.
 
H

Howard Kaikow

Simon said:
Hi, I'm trying to fix ths error in my Word macros. Its happeing because I'm
using an Office 2003 property that isn't supported on Office XP:-
ActiveWindow.View.ShadeEditableRanges = False
Is there any way I can prevent Office XP and earlier versions from
attempting to compile the code they don't support?

Put the code in a separate code module and do not call that procedure unless
you are in te right version of Word.

You will still recive a compile error, but the code will run correctly as
long as you don't call the procedure in the wrong version.
 
S

Simon

Howard Kaikow said:
Put the code in a separate code module and do not call that procedure unless you are in te right version of Word.

You will still recive a compile error, but the code will run correctly as
long as you don't call the procedure in the wrong version.

I cannot have compile errors poping up every time users open my documents!

MS should be making earlier versions of Office ignore any properties or
methods they don't support. Otherwise how is anyone going to be able to use
the newer features?
 
J

Jonathan West

Simon said:
I cannot have compile errors poping up every time users open my documents!

MS should be making earlier versions of Office ignore any properties or
methods they don't support. Otherwise how is anyone going to be able to
use
the newer features?

No, I think you have misunderstood Howard. You organise things as follows

1. Any code that contains objects that only work in (say) Office 11 should
be put in a module (call it Office11stuff or something like that. The
routines in this module should be absolutely the bare minimum.

2. Whenever you want a general-purpose routine to make use of an Office 11
feature, you call it like this

If Application.Version = 11 Then
Office11Action
Else
Office10Action
End If

Office11Action is in the Office11stuff module.

You will only get a compile error in such a case if you have the project
open in an old version of Word, and you decide to select the Compile option
from the Debug menu.

As your Office 10 users will not be expected to open the VBA editor, and the
Office 11 modules will never therefore get executed. Compile errors only
happen when an individual module is executed that contains unavailable
features


--
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
 
S

Simon

Howard Kaikow said:
You do not get compile errors if you do what I stated.

Pardon my ignorance but if you say "You will still recive a compile error" I
kinda expect that I will get a compile error. However, from the other reply
from Johnathan West, clarifying your suggestion, it seems that it will work
as I wanted, so thank you very much indeed!
 
H

Howard Kaikow

Simon said:
Pardon my ignorance but if you say "You will still recive a compile error" I
kinda expect that I will get a compile error. However, from the other reply
from Johnathan West, clarifying your suggestion, it seems that it will work
as I wanted, so thank you very much indeed!

You still get a compier error, if you ask VBA to compile while in design
view, in which case, VBA will compile all code.

At run-time, VBA only interprets the code in code components that are
actually executed. so there are no compile errors if you isolate the code
for later versions in a separate module, as long as you do not try to
execute any procedure in that module at run time.
 
S

Simon

Howard Kaikow said:
You still get a compier error, if you ask VBA to compile while in design
view, in which case, VBA will compile all code.

At run-time, VBA only interprets the code in code components that are
actually executed. so there are no compile errors if you isolate the code
for later versions in a separate module, as long as you do not try to
execute any procedure in that module at run time.

And it works! Thanks very much for the tip. This is as close to conditional
compilation as you can get in VBA!
 

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