Selecccionar Impresora
Necesito seleccionar una impresora y establecerla como predeterminada desde código sin utilizar ningun control solo con codigo.
yo tenia la misma duda y me pasaron este codigo:
Public Function setDefaultPrinter(ByVal v_strPrinterPath As String) As Boolean
'*******************************************************************
' Name : SetDefaultPrinter
' Purpose : Sets the default printer on the local machine
' Parameters : v_strPrinterPath : Path of printer to set as default
' Returns : TRUE if successful, FALSE if not
' Author : Andy Stevens
' Date : August 2002
'*******************************************************************
'Declare local variables
Dim blnReturn As Boolean
Dim objNetwork As Object
'Declare local constants
Const FUNCTION_NAME As String = "modPrinters.SetDefaultPrinter"
On Error GoTo ErrorHandler
'Set the default return value
blnReturn = False
'Create the Script Host object
Set objNetwork = CreateObject("WScript.Network")
'Set the printer to be the default
objNetwork.setDefaultPrinter v_strPrinterPath
'Printer set
blnReturn = True
CleanExit:
'Kill the script host object
If Not objNetwork Is Nothing Then
Set objNetwork = Nothing
End If
setDefaultPrinter = blnReturn
Exit Function
ErrorHandler:
'Display the error
MsgBox "Error No: " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
"Has occured in " & FUNCTION_NAME & vbCrLf & _
"Please contact Technical Support", vbOKOnly + vbCritical, App.Title
Resume CleanExit
End Function
ademas otra persona me dijo que era mas facil usando commondialog.printer pero eso no lo use ya que la funcion anterior me funcionaba
esperi que te sirva de algo alguna de las dos cosas
Public Function setDefaultPrinter(ByVal v_strPrinterPath As String) As Boolean
'*******************************************************************
' Name : SetDefaultPrinter
' Purpose : Sets the default printer on the local machine
' Parameters : v_strPrinterPath : Path of printer to set as default
' Returns : TRUE if successful, FALSE if not
' Author : Andy Stevens
' Date : August 2002
'*******************************************************************
'Declare local variables
Dim blnReturn As Boolean
Dim objNetwork As Object
'Declare local constants
Const FUNCTION_NAME As String = "modPrinters.SetDefaultPrinter"
On Error GoTo ErrorHandler
'Set the default return value
blnReturn = False
'Create the Script Host object
Set objNetwork = CreateObject("WScript.Network")
'Set the printer to be the default
objNetwork.setDefaultPrinter v_strPrinterPath
'Printer set
blnReturn = True
CleanExit:
'Kill the script host object
If Not objNetwork Is Nothing Then
Set objNetwork = Nothing
End If
setDefaultPrinter = blnReturn
Exit Function
ErrorHandler:
'Display the error
MsgBox "Error No: " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
"Has occured in " & FUNCTION_NAME & vbCrLf & _
"Please contact Technical Support", vbOKOnly + vbCritical, App.Title
Resume CleanExit
End Function
ademas otra persona me dijo que era mas facil usando commondialog.printer pero eso no lo use ya que la funcion anterior me funcionaba
esperi que te sirva de algo alguna de las dos cosas
