Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can a Word Macro Determine which Operating System?

Status
Not open for further replies.

cheriberi

Technical User
May 27, 2003
60
US
I need to find out if I can do the following in a Word macro:

1) Determine which operating system is used. If Windows XP, I need to save a print file (.prn or .ps) using a specific printer. If not Windows XP, it needs to be saved as a print file using a different printer.

2) Reset to the default printer.

Hope someone can help with this.
 
1) Try something like this:
Set oSh = CreateObject("WScript.Shell")
Set oEx = oSh.Exec("%COMSPEC% /C ver")
Do While oEx.Status = 0
DoEvents
Loop
While Len(os) < 1
os = Replace(oEx.StdOut.ReadLine, vbCrLf, "")
Wend
If InStr(os, "XP") Then MsgBox os
2) Play with the Application.ActivePrinter property

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Can you include a little explanation of what each line of the code does? That'll help me figure out (hopefully) where to select the printer.

Thanks for your help with this!!
 
What have you so far ?
In your object browser, press the F1 key on the PrintOut method of the Document object.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
I got on error on the following line of code which says sub or function not defined:

os = [COLOR=black yellow]Replace[/color](oEx.StdOut.ReadLine, vbCrLf, "")

FYI: This macro may be run on a XP or NT machine.
 
Seems your word version is older than expected. Doesn't matter, just get rid of them like this:
os = oEx.StdOut.ReadLine
keeping this statement in the while loop.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Hi cheriberi,

You can check [blue]System.Version[/blue]. It returns two numbers separated by a decimal point representing the major version and the minor version. I don't know all the values but I think XP is 5.1.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Using the previous code, I saw something flash by quickly on my NT machine, but couldn't see what it was. On the XP machine, I got an automation error on the "set oSH..." line of code.

I used the following code on both machines and got the correct messages.

Code:
If System.Version = "5.1" Then
    MsgBox "This is an XP machine."
Else
    MsgBox "This is not an XP machine."
End If

Would it be a good idea to say if the version is 5.1 or greater? Is that likely to be needed in the future? Would the following be correct?

Code:
If System.Version => "5.1" Then

Also, how can I get the macro to select a specific printer driver if it's an XP machine?

Thanks for all your help!
 
Use something like

sub PrintStuff()

If System.Version >= "5.1" Then
tempPrinterName="Samsung SF4500 Series on LPT1:"
Else
tempPrinterName="Auto Fujitsu PrintPartner 16DV on EJB on Ne01:"
End If

ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= tempPrinterName, PrintToFile:=True, Collate:=True, PrToFileName:= tempWhatEverNameYouWant


Application.ActivePrinter = whatEverPrinterWasDefaultBefore

end sub


Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top