Try something like this:
Code:
Private Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
Private Sub Command1_Click()
Dim prn As Printer
Dim blnIsFound As Boolean
Dim strBuffer As String
If machinename = "Rm10-17" Then
strBuffer = "Room 10 printer"
'Check if the printer exists
For Each prn In Printers
If UCase(strBuffer) = UCase(prn.DeviceName) Then
strBuffer = strBuffer & "," & prn.DriverName & "," & prn.Port
blnIsFound = True
Exit For
End If
Next
'If printer exists, then change it to be default
If blnIsFound Then
Call WriteProfileString("windows", "device", strBuffer)
MsgBox "Succesfully changed printer " & strCommand
End
End If
End If
End Sub
Assuming that the "Room 10 printer" is a valid printer.