VERSION 5.00
Begin VB.Form Form_cambiar_impresora_predeterminada 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Cambiar impresora predeterminada"
   ClientHeight    =   6270
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   5880
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   6270
   ScaleWidth      =   5880
   Begin VB.Frame Frame2 
      Caption         =   "Pagina de prueba"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   2775
      Left            =   120
      TabIndex        =   4
      Top             =   3360
      Width           =   5655
      Begin VB.CommandButton Command2 
         Caption         =   "Imprimir pagina de prueba"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   120
         TabIndex        =   6
         Top             =   2160
         Width           =   5415
      End
      Begin VB.TextBox Text1 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   12
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   1695
         Left            =   120
         MultiLine       =   -1  'True
         TabIndex        =   5
         Text            =   "Form_cambiar_impresora_predeterminada.frx":0000
         Top             =   360
         Width           =   5415
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Cambiar impresora predeterminada"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   3135
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   5655
      Begin VB.CommandButton Command1 
         Caption         =   "Establecer impresora como predeterminada"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   120
         TabIndex        =   2
         Top             =   2520
         Width           =   5415
      End
      Begin VB.ListBox List1 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   1740
         ItemData        =   "Form_cambiar_impresora_predeterminada.frx":00EE
         Left            =   120
         List            =   "Form_cambiar_impresora_predeterminada.frx":00F0
         TabIndex        =   1
         Top             =   600
         Width           =   5415
      End
      Begin VB.Label Label1 
         Caption         =   "Listado de impresoras"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   3
         Top             =   360
         Width           =   4335
      End
   End
End
Attribute VB_Name = "Form_cambiar_impresora_predeterminada"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
   Private Function establecer_impresora(ByVal NamePrinter As String) As Boolean

   On Error GoTo errSub
   
        'Variable de referencia
        Dim obj_Impresora As Object
   
        'Creamos la referencia
        Set obj_Impresora = CreateObject("WScript.Network")
            obj_Impresora.SetDefaultPrinter NamePrinter
  
       Set obj_Impresora = Nothing
  
           'La función devuelve true y se cambió con éxito
           establecer_impresora = True
           MsgBox "La impresora se cambió correctamente", vbInformation
       Exit Function
  
'MsgBox obj_Impresora
   'Error al cambiar la impresora
errSub:
   If Err.Number = 0 Then Exit Function
      establecer_impresora = False
      MsgBox "error: " & Err.Number & Chr(13) & "Description: " & Err.Description
      On Error GoTo 0
   End Function
  
   Private Sub Command1_Click()

   'Le enviamos la impresora que se encuentre seleccionada en el control List1
   If List1.Selected(List1.ListIndex) Then
      establecer_impresora List1
     ' MsgBox devuelve_equipo
   End If
   End Sub
  
Private Sub Command2_Click()
 ' Colocar un List1 y un Command1
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    

   
   
'        If List1.ListIndex <> -1 Then
'           Call Establecer(List1.Text)
'           MsgBox "Se usará la impresora: " & _
'                  Printer.DeviceName & " para imprimir el texto", vbInformation
  
          ' imprime el texto de prueba en la impresora seleccionada en List1
          Printer.Print Text1
          Printer.EndDoc
'       End If
   
End Sub

   Private Sub Form_Load()

   Dim X As Printer, impr As String
  
   'Listamos en el control List1 las impresoras instaladas
   For Each X In Printers
       List1.AddItem X.DeviceName
   Next
  
   Command1.Caption = " Seleccionar la impresora  y establecer como predeterminada "
   End Sub

Private Function devuelve_equipo() As String
    Dim I As Integer
    'Dim pos_fin
    Dim impresora As String
    impresora = List1.Text
    I = 3
    While Mid(impresora, I, 1) <> "\"
        I = I + 1
    Wend
    I = I - 3
    devuelve_equipo = Mid(impresora, 3, I)
    'MsgBox List1.Text
End Function
