You could add a procedure to the ThisWorkbook/ThisDocument
module of your personal.xls/normal.dot that would detect if you were at home and set the printer default appropriately.
I've not tested this, but USERDOMAIN
(index 30) should be suitable for this purpose. The following code should give you a rough idea of what is required to do this.
Sub checkDomain()
Dim desiredPrinter As String
If Environ(30) = "USERDOMAIN=YOURWORKDOMAIN" Then
'Set work default printer
desiredPrinter = "\\NetworkAddress\Work Printer on Ne04:"
Else
'Set home default printer
desiredPrinter = "Microsoft XPS Document Writer on Ne01:"
End If
If Not Application.ActivePrinter = desiredPrinter Then
Application.ActivePrinter = desiredPrinter
End If
End Sub
Note that the ports will likely be different on your PC, you can run the following code to check what VBA thinks your printers are called.
Sub PrinterList()
Dim objWMIService
Dim colInstalledPrinters
Dim objPrinter
Dim strPrinterName As String
Dim strComputer As String
strPrinterName = Application.ActivePrinter
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer ")
For Each objPrinter In colInstalledPrinters
If objPrinter.PrinterStatus = 1 Or objPrinter.PrinterStatus = 2 Or objPrinter.PrinterStatus = 7 Then
Debug.Print "offline:" & objPrinter.Name
Else
If InStr(strPrinterName, objPrinter.Name) Then
Debug.Print objPrinter.Name & "*"
Else
Debug.Print objPrinter.Name
End If
End If
Next
End Sub
This will list all installed printer names in the Immediate window of the Visual Basic Editor (CTRL+G for the Immediate window if you're not very familiar with VBA)
Just made that change, but I'm currently connected to the network. I'll check if it works later, thanks. – Roee Adler – 2009-09-14T13:18:21.440
happy you're all set :) – warren – 2009-09-20T09:02:24.210