sábado, 27 de mayo de 2023

EXCEL INGRESAR DATOS CON FOTO





Option Explicit
Dim ArchivoIMG As String
Private Sub btn_TomarFoto_Click()
Dim RetVal, base, i, picName, picPath, picNumber
Hoja1.Cells(1, 1) = Hoja1.Cells(1, 1) + 1
picNumber = Hoja1.Cells(1, 1)
picName = "Image" & picNumber & ".jpg"
ChDir (ActiveWorkbook.Path)
base = ActiveWorkbook.Path & "\"
picPath = base & picName
RetVal = Shell(base & "CommandCam.exe /filename """ & picPath & """", vbHide)
    For i = 0 To 5
        Aviso "Espere..." & i
        Application.Wait (Now + TimeValue("00:00:01"))
    Next
Aviso "Listo!!!"
ArchivoIMG = picPath
frm_Clientes.fotografia.Picture = LoadPicture(ArchivoIMG)
    cmd_Agregar.SetFocus
End Sub
Private Sub cmd_Agregar_Click()
    Dim i As Integer
    Sheets("Clientes").Activate
    Dim fCliente As Integer
    fCliente = nCliente(cbo_Nombre.Text)
    If fCliente = 0 Then
        Do While Not IsEmpty(ActiveCell)
            ActiveCell.Offset(1, 0).Activate ' si el registro no existe, se va al final.
        Loop
    Else
        Cells(fCliente, 1).Select  ' cuando ya existe el registro, cumple esta condición.
    End If
    'Aqui es cuando agregamos o modificamos el registro
    Application.ScreenUpdating = False
    ActiveCell = cbo_Nombre
'    ActiveCell.Offset(0, 1) = txt_Direccion
    ActiveCell.Offset(0, 1) = ArchivoIMG
    Application.ScreenUpdating = True
    LimpiarFormulario
    cbo_Nombre.SetFocus
End Sub

Private Sub cbo_Nombre_Change()
On Error Resume Next
    If nCliente(cbo_Nombre.Text) <> 0 Then
        Sheets("Clientes").Activate
        Cells(cbo_Nombre.ListIndex + 2, 1).Select
'        txt_Direccion = ActiveCell.Offset(0, 1)
        fotografia.Picture = LoadPicture("")
        fotografia.Picture = LoadPicture(ActiveCell.Offset(0, 1))
        ArchivoIMG = ActiveCell.Offset(0, 1)
    Else
 '       txt_Direccion = ""
        ArchivoIMG = ""
        fotografia.Picture = LoadPicture("")
    End If
End Sub
Private Sub cbo_Nombre_Enter()
CargarLista
End Sub
Sub CargarLista()
   cbo_Nombre.Clear
    Sheets("Clientes").Select
    Range("A2").Select
    Do While Not IsEmpty(ActiveCell)
        cbo_Nombre.AddItem ActiveCell.Value
        ActiveCell.Offset(1, 0).Select
    Loop
End Sub
Sub LimpiarFormulario()
    CargarLista
    cbo_Nombre = ""
'    txt_Direccion = ""
    ArchivoIMG = ""
    lbl_Wait.Caption = ""
End Sub
MODULO 1
Option Explicit
Sub registrar()
    Load frm_Clientes
    Sheets("clientes").Activate
    frm_Clientes.Show
End Sub

Function nCliente(nombre As String) As Integer
    Application.ScreenUpdating = False
    
    Sheets("Clientes").Activate
    Range("A2").Activate
    
    
    nCliente = 0
    
    Do While Not IsEmpty(ActiveCell)
        If nombre = ActiveCell Then
            nCliente = ActiveCell.Row
        End If
        ActiveCell.Offset(1, 0).Select
    Loop
    
    
    Application.ScreenUpdating = True
    
End Function

Sub Aviso(msg As String)
    frm_Clientes.lbl_Wait.Caption = msg
End Sub

MODULO 2
Function EXTRAEX(txt As String, flg As Boolean) As String
With CreateObject("VBScript.RegExp")
    .Pattern = IIf(flg = True, "\d+", "\D+")
    .Global = True
    EXTRAEX = .Replace(txt, "")
End With
End Function
HOJA1


Private Sub CommandButton1_Click()
frm_Clientes.Show
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
 
If Target.Column < 3 Then
    Cells(Target.Row, 3).Value = Now
End If
 
End Sub



No hay comentarios:

Publicar un comentario