Sub Imagen13_Haga_clic_en()
Dim Izq As Single, Arr As Single, Ancho As Single, Alto As Single
Dim rutaArchivo As String
Dim Email As CDO.Message
Dim t As Single
Application.DisplayAlerts = False
Application.ScreenUpdating = False
ActiveSheet.Unprotect "4324"
'--- GENERAR IMAGEN DEL RECIBO ---
With Range("H7:R34")
Izq = .Left: Arr = .Top: Ancho = .Width: Alto = .Height
.CopyPicture
End With
With ActiveSheet.ChartObjects.Add(Izq, Arr, Ancho, Alto)
.Activate
.Chart.Paste
'---- RUTA DEL ARCHIVO (CORREGIDO) ----
rutaArchivo = "C:\Users\Usuario\Google Drive\LOCACIONES\REC. PROPIETARIOS\" & _
Format(Range("Q20"), "mmmYY") & " - " & _
Range("Q9") & " - " & _
Range("P17") & " - " & _
Range("K19") & ".JPG"
.Chart.Export rutaArchivo
.Delete
End With
'Guardar ruta en AK30 por compatibilidad
Range("AK30").Value = rutaArchivo
'--- PEGAR BLOQUE DE DATOS ---
Range("AH6").Copy
Range("AH9").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Range("Y7:AI33").Copy
Range("H7").PasteSpecial xlPasteAll
ActiveSheet.Protect "4324"
ActiveWorkbook.Save
'--- PREPARAR ENVÍO DEL MAIL ---
Set Email = New CDO.Message
correo_origen = "nqn.negocios@gmail.com"
Clave_correo_origen = "wkfhaapcnjljbwju"
correo_destino = Range("AK27").Value
Asunto = Range("AK28")
Mensaje = Range("AK29")
Email.Configuration.Fields(cdoSMTPServer) = "smtp.gmail.com"
Email.Configuration.Fields(cdoSendUsingMethod) = 2
With Email.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = correo_origen
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = Clave_correo_origen
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
End With
'--- VALIDAR ARCHIVO ANTES DE ENVIAR ---
t = Timer
Do While Dir(rutaArchivo) = "" And Timer - t < 5
DoEvents
Loop
If Dir(rutaArchivo) = "" Then
MsgBox "ERROR: El archivo no se generó: " & rutaArchivo, vbCritical
Exit Sub
End If
'--- ENVIAR MAIL ---
With Email
.To = correo_destino
.From = correo_origen
.Subject = Asunto
.TextBody = Mensaje
.Configuration.Fields.Update
.AddAttachment rutaArchivo
On Error Resume Next
.Send
End With
End Sub
Sub powerbuttonINQ()
Dim Izq As Single, Arr As Single, Ancho As Single, Alto As Single
Dim rutaArchivo As String
Dim Email As CDO.Message
Dim t As Single
Application.DisplayAlerts = False
Application.ScreenUpdating = False
ActiveSheet.Unprotect "4324"
'--- GENERAR IMAGEN DEL RECIBO ---
With Range("H7:R33")
Izq = .Left: Arr = .Top: Ancho = .Width: Alto = .Height
.CopyPicture
End With
With ActiveSheet.ChartObjects.Add(Izq, Arr, Ancho, Alto)
.Activate
.Chart.Paste
rutaArchivo = "C:\Users\Usuario\Google Drive\LOCACIONES\REC. INQUILINOS\" & _
Format(Range("Q20"), "mmmYY") & " - " & _
Range("Q9") & " - " & _
Range("P17") & " - " & _
Range("J17") & ".JPG"
.Chart.Export rutaArchivo
.Delete
End With
Range("AK30").Value = rutaArchivo
Range("AH6").Copy
Range("AH9").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Range("Y7:AI33").Copy
Range("H7").PasteSpecial xlPasteAll
ActiveSheet.Protect "4324"
ActiveWorkbook.Save
'--- EMAIL CONFIG ---
Set Email = New CDO.Message
correo_origen = "nqn.negocios@gmail.com"
Clave_correo_origen = "wkfhaapcnjljbwju"
correo_destino = Range("AK27").Value
Asunto = Range("AK28")
Mensaje = Range("AK29")
Email.Configuration.Fields(cdoSMTPServer) = "smtp.gmail.com"
Email.Configuration.Fields(cdoSendUsingMethod) = 2
With Email.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = correo_origen
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = Clave_correo_origen
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
End With
'--- VERIFICAR ARCHIVO ---
t = Timer
Do While Dir(rutaArchivo) = "" And Timer - t < 5
DoEvents
Loop
If Dir(rutaArchivo) = "" Then
MsgBox "ERROR: El archivo no se generó: " & rutaArchivo, vbCritical
Exit Sub
End If
'--- ENVIAR ---
With Email
.To = correo_destino
.From = correo_origen
.Subject = Asunto
.TextBody = Mensaje
.Configuration.Fields.Update
.AddAttachment rutaArchivo
On Error Resume Next
.Send
End With
End Sub
Por
JSDJSD , · publicado el 5 de diciembre 5 dic
Hola a todos.
Mi primera participación en el foro es para solicitaros, como a la gran mayoría de los autodidactas y profanos en esta materia nos ocurre, ayuda sobre el código de Visual Basic para Excel 2010.
Conseguí el siguiente código que imprime los datos de varios registros (filas) de una hoja. Funciona perfectamente pero encuentro un pequeño inconveniente: imprime siempre con la impresora establecida por defecto. Me indica cuántos registros se van a imprimir y sin darme más opciones los imprime directamente todos en la impresora habilitada por defecto.
Agradecería muchísimo que alguien me dijera qué debo añadir y/o cambiar para que cuando ejecute la macro me aparezca la ventana de selección de impresoras y elegir la que considere en un momento dado.
Feliz semana para todos!!
Sub ImprimirD()
Application.ScreenUpdating = False
Worksheets("IMPRIME").Visible = True
Worksheets("IMPRIME").Protect _
Password:="paraprint", _
UserInterfaceOnly:=True
If UCase(ActiveSheet.Name) <> "FACTURADAS" Then Exit Sub
Dim wksCli As Worksheet, wksFic As Worksheet
Dim rngO As Range, rngArea As Range
Dim lngFilas As Long, intRespuesta As Integer, n As Long
Set wksCli = Worksheets("Facturadas")
Set wksFic = Worksheets("IMPRIME")
Set rngO = Selection
For Each rngArea In rngO.Areas
lngFilas = lngFilas + rngArea.Rows.Count
Next rngArea
intRespuesta = MsgBox(prompt:="Se imprimirán " & lngFilas & " filas.", Buttons:=vbOKCancel + vbInformation)
If intRespuesta = vbCancel Then Exit Sub
For Each rngArea In rngO.Areas
For n = 1 To rngArea.Rows.Count
With wksFic
.Range("AH13") = rngArea.Cells(n, 1)
.Range("BE33") = rngArea.Cells(n, 2)
.Range("P46") = rngArea.Cells(n, 7)
.Range("H46") = rngArea.Cells(n, 8)
.Range("C46") = rngArea.Cells(n, 9)
.Range("P50") = rngArea.Cells(n, 10)
.Range("H50") = rngArea.Cells(n, 11)
.Range("C50") = rngArea.Cells(n, 12)
.Range("P54") = rngArea.Cells(n, 13)
.Range("H54") = rngArea.Cells(n, 14)
.Range("C54") = rngArea.Cells(n, 15)
.Range("P58") = rngArea.Cells(n, 16)
.Range("H58") = rngArea.Cells(n, 17)
.Range("C58") = rngArea.Cells(n, 18)
.Range("S67") = rngArea.Cells(n, 19)
.Range("C67") = rngArea.Cells(n, 20)
.Range("K67") = rngArea.Cells(n, 21)
.Range("K79") = rngArea.Cells(n, 23)
End With
wksFic.PrintOut 'Application.Dialogs(xlDialogPrint).Show
Next n
Next rngArea
Set rngArea = Nothing
Set rngO = Nothing
Set wksFic = Nothing
Set wksCli = Nothing
Worksheets("IMPRIME").Visible = False
Sheets("Facturadas").Select
Range("A1").Select
Application.ScreenUpdating = True
End Sub