Mac Excel compile error method or data member not found

R

rjbayha

I am working on a VBA application for Excel that should work in
Windows versions 2000 thru 2010, and Mac 2004. There is no problem
with PC Excel - only Mac Excel 2004.

In my dBase3+ and FoxBase+ days, I would create and store a line of
code to a variable based on If...Else...EndIf conditions and then
execute the code via the variable. For example:

Foxbase code start ---------------------------------------
If County = "KERN"
mIndex = "Index On Well_Number For County = "KERN""
Else
mIndex="" 'for do nothing
EndIf

'the first character "&" means execute code stored in mIndex
&mIndex
Foxbase code end ---------------------------------------

Can VBA code be store to a variable to get around compile errors?

First example is for showing a Userform Modeless-Model which Mac Excel
hates (ie, Userform1.Show vbModeles, or vbModal, or 0, or 1 results in
a Mac Excel 2004 compile error).

VBA code starts ------------------------------------------------
if left(application.operatingsystem,3) = "Mac" then
mUserform = "Userform1.Show"
else
mUserform = "Userform1.Show vbModeless"
end if

&mUserform 'variable to execute the code in mUserform
VBA code starts ------------------------------------------------

The second example is to deactivate the autosave and-or autobackup
setting. Mac Excel 2004 hates ThisWorkbook.EnableAutoRecovery (compile
error: method or data member not found)

VBA code starts ------------------------------------------------
if left(application.operatingsystem,3) = "Mac" then
mSaveSet = "Application.SaveInterval = 0"
else
if application.version = "9.0" then
mSaveSet = "Application.AddIns("Autosave Add-in").Installed = False"
else
mSaveSet = "ThisWorkbook.EnableAutoRecover = False"
end if
end if

&mSaveSet 'variable to execute the code in mSaveSet
VBA code ends ------------------------------------------------

Again, I want to save VBA code to a variable based on condition(s) for
later execution, and to avoid compiler errors. Or, is there another
work-around.
 

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