Run certain macros based on operating system

  • Thread starter Thread starter Mr. Smith
  • Start date Start date
M

Mr. Smith

I need a workbook with macros that need to run on machines
with older versions of Windows NT 4 and others on Windows XP
Professional.
Instead of making two separate workbooks, I'd like an IF-THEN
scenario using the =INFO("osversion") formula to determine the
operating system and if it's not XP -- I get "Windows (32-bit) NT
5.01" with the osversion formula on the XP machines -- to run the
NT-compatible macro.
But, being a newbie, I don't know how to go about that.
I Googled for an example, but came up empty. I would have to
imagine someone else has come across this problem before.
Thanks for any help/pointers, etc.
 
if lcase(Application.OperatingSystem) = lcase("Windows (32-bit) NT 5.01") then
'do xp stuff
else
'do non-xp stuff
end if

Just curious -- what will you be using that depends on the operating system
version?
 
I was going to say Conditional compilation,
e.g. < In a module >
Public Enum OSVersion
OS_Unknown = 0
OS_NT = 4
OS_2K = 5
OS_XP = 6
End Enum

#Const OS =5
</ In a module >

<Wherever you need to check the OS version>
#If OS = OS_NT Then
'NT code
#ElseIf OS = OS_2K Then
MsgBox "W2K code only"
'XP code
#ElseIf OS = OS_XP Then
'XP code
#Else
'Exit/warning
#End If
</Wherever you need to check the OS version>

But...
Seems that these constants cannot be not Public, so you will have to add a
"#Const OS =5" to each module that will use it.
Also, these constant do not seem to like comparison to an enum, so you have
to the numeric values.

So you will have to change the value of "OS" on each of the modules,
depending on the platform that it is destined for.

But as dave enquired, is this really necessary ?

NickHK
 
Dave:
Thanks. I'll give it a whirl.
One other question: Is there a way for the macro to just look
at "Windows (32-bit) NT 5" and "Windows (32-bit) NT 4" portion to
determine if it's an XP or NT machine? (I want to be sure it will run
whether it's 5.01 or 5.02, etc.)
Where I work, we have a mix of NT4 machines that should be in
a Dumpster and XP Pro workstations. Because people jump around, they'd
need this workbook to work wherever they are.
Specifically, the workbook with the macros does its thing then
e-mails the resulting workbook. With XP, I have a macro that calls the
mail server (bypassing the need for an e-mail client) and will
silently send the workbook. This is the way I'd prefer, but on NT, it
doesn't work. I have another macro that does, which uses Outlook to
mail the file. The macro that works on NT, doesn't work on XP, and
vice versa.
I'm sure there are easier ways to do this stuff but I'm not
savvy with Excel.
Thanks again for the help.
 
Couldn't you just look at the first xx characters:

if lcase(left(application.operatingsystem,19)) _
= lcase("Windows (32-bit) NT") then

or

if lcase(application.operatingsystem) like lcase("Windows (32-bit) NT*") then
....

===========
Ron de Bruin has a bunch of notes about emailing via code:
http://www.rondebruin.nl/sendmail.htm

I think he uses CDO (I've never used it) to overcome some problems with
different versions of Outlook.
 
Dave:
I believe I got the code to e-mail without a client from Ron's
site. My preference is to do it without a client, which may come back
to bite me.
Thanks again for your help.
 

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

Back
Top