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
Muy Buenas amigos del foro:
Estoy intentando capturar datos mediante un formulario pero al gardar los datos me presenta un error, el codigo que he escrito es el siguiente:
Private Sub CommandButton6_Click()
Dim fecha As Date
Dim sucursal As String
Dim ingpart As Double
Dim factpart As Double
Dim inginst As Double
Dim factinst As Double
Dim exapart As String
Dim exapsv15 As String
Dim exapsv10 As String
Dim exaemp As String
Dim exaprom As String
Dim exacort As String
Dim exaoftalm As String
Dim valexapart As Double
Dim valexapsv15 As Double
Dim valexapsv10 As Double
Dim valexaemp As Double
Dim valexaprom As Double
Dim valexaoftalm As Double
Dim valtotexa As Double
fecha = Txtfecha
sucursal = Txtsucursal
ingpart = Txtingpart
factpart = Txtfactpart
inginst = Txtinginst
factinst = Txtfactinst
exapart = Txtexapart
exapsv15 = Txtexapsv15
exapsv10 = Txtexapsv10
exaemp = Txtexaemp
exaprom = Txtexaprom
exacort = Txtexacort
exaoftalm = Txtexaoftalm
valexapart = Txtvalexapart
valexapsv15 = Txtvalexapsv15
valexapsv10 = Txtvalexapsv10
valexaemp = Txtvalexaemp
valexaprom = Txtvalexaprom
valexaoftalm = Txtvalexaoftalm
valtotexa = Txtvaltotexa
Ultimafila = ActiveSheet.UsedRange.Rows - 1 + ActiveSheet.UsedRange.Rows.Count
Cells(ultmafila + 1, 1) = fecha
Cells(ultmafila + 1, 2) = sucursal
Cells(ultmafila + 1, 3) = ingpart
Cells(ultmafila + 1, 4) = factpart
Cells(ultmafila + 1, 5) = inginst
Cells(ultmafila + 1, 6) = factinst
Cells(ultmafila + 1, 7) = exapart
Cells(ultmafila + 1, 8) = exapsv15
Cells(ultmafila + 1, 9) = exapsv10
Cells(ultmafila + 1, 10) = exaemp
Cells(ultmafila + 1, 11) = exacort
Cells(ultmafila + 1, 12) = exaprom
Cells(ultmafila + 1, 13) = exaoftalm
Cells(ultmafila + 1, 14) = valexapart
Cells(ultmafila + 1, 15) = valexapsv15
Cells(ultmafila + 1, 16) = valexapsv10
Cells(ultmafila + 1, 17) = valexaemp
Cells(ultmafila + 1, 18) = valexaprom
Cells(ultmafila + 1, 19) = valexaoftalm
Cells(ultmafila + 1, 20) = valtotexa
Txtfecha.SetFocus
End Sub
al guardarlo me presenta el siguiente error: se ha producido el error "13" en tiempo de ejecución, no coinciden los tipos.
al darle depurar se me ubica en la siguiente linea:
valexaoftalm = Txtvalexaoftalm
valtotexa = Txtvaltotexa
Ultimafila = ActiveSheet.UsedRange.Rows - 1 + ActiveSheet.UsedRange.Rows.Count ESTA ES LA FILA DEL ERROR
Cells(ultmafila + 1, 1) = fecha
Cells(ultmafila + 1, 2) = sucursal
Cells(ultmafila + 1, 3) = ingpart
Cells(ultmafila + 1, 4) = factpart
Cells(ultmafila + 1, 5) = inginst
Cells(ultmafila + 1, 6) = factinst
Cells(ultmafila + 1, 7) = exapart
Cells(ultmafila + 1, 8) = exapsv15
Cells(ultmafila + 1, 9) = exapsv10
Cells(ultmafila + 1, 10) = exaemp
Mi problema es que no encuentro la incongruencia del codigo, me pueden ayudar a resolver esta situación, y de antemano les agradesco por su ayuda.