Un subfuntion que use las variables del userformactivo

Hola
Como estas
Que pena lo canson, tu me colaboraste con el dato de una subrutina que estaba creado para que no me devolviera ningún dato.
Pues esta subrutina me la abren varios userform no uno solo, y quiero que según el user form que lo llame tome de ese por ejemplo el textbox1.
Lo que pasa es que en este momento no me la toma y tengo que poner userform1.textbox1.value = xxxx y eso me limita esa subrutina y no la puedo usar en otros userform
esta es mi subrutina de antemano gracias por tu valiosa ayuda
Public Function contabilizar_fact(cta, doc, debe, haber)
CLASE = Left(cta, 1)
GRUPO = Left(cta, 2)
cuenta = Left(cta, 4)
TIPO = Len(cta)
If TIPO = 6 Then
    cuenta = cta ' presumimos que es una subcuenta
End If
If CLASE = 1 Then
    CLASE = "ACTIVO"
ElseIf CLASE = 2 Then
    CLASE = "PASIVO"
ElseIf CLASE = 3 Then
    CLASE = "PATRIMONIO"
ElseIf CLASE = 4 Then
    CLASE = "INGRESOS"
ElseIf CLASE = 5 Then
    CLASE = "GASTOS"
ElseIf CLASE = 6 Then
    CLASE = "COSTOS"
ElseIf CLASE = 8 Then
    CLASE = "CTAS_DE_ORDEN"
ElseIf CLASE = 9 Then
    CLASE = "CTAS_DE_ORDEN"
End If
ruta = "Y:\"
carpeta = "CONTABILIDAD"
Libro = CLASE
texto = ruta & carpeta & "\" & Libro & ".xlsx"
Workbooks.Open texto, UpdateLinks:=False, Password:="rON44991043"
Workbooks(Libro & ".xlsx").Sheets(cuenta).Activate
Sheets(cuenta).Select
Range("A2").Select  'selecciono la celda A2
Selection.EntireRow.Insert
Range("A2").Value = (Range("A3")) + 1
Cells(2, 2).Value = doc '
Cells(2, 3).Value = FACTURACION.TextBox109 ' NO DE documento
Cells(2, 4).Value = FACTURACION.TextBox37 ' nit a quien lo aplicamos
Cells(2, 5).Value = FACTURACION.TextBox38 ' nombre
Cells(2, 6).Value = FACTURACION.TextBox108 ' fEcha de aplicacion
Cells(2, 7).Value = Val(debe) 'VALOR  debe
Cells(2, 8).Value = Val(haber) 'VALOR  haber
Cells(2, 10).Value = Now()
Cells(2, 11).Value = MENU.TextBox_USUARIO.Value
If CLASE = "ACTIVO" Then ' aumenta por el debito
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) + (Val(Cells(2, 7).Value)) - (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO OK
ElseIf CLASE = "PASIVO" Then ' aumenta por el credito
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) - (Val(Cells(2, 7).Value)) + (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO OK
ElseIf CLASE = "PATRIMONIO" Then ' aumenta por el credito
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) - (Val(Cells(2, 7).Value)) + (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO
ElseIf CLASE = "INGRESOS" Then ' aumenta por el credito
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) - (Val(Cells(2, 7).Value)) + (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO OK
ElseIf CLASE = "GASTOS" Then ' aumenta por el debito
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) + (Val(Cells(2, 7).Value)) - (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO
ElseIf CLASE = "COSTOS" Then ' aumenta por el debito
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) + (Val(Cells(2, 7).Value)) - (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO OK
ElseIf CLASE = "CTAS_DE_ORDEN" Then
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) - (Val(Cells(2, 7).Value)) + (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO
ElseIf CLASE = "CTAS_DE_ORDEN" Then
    Cells(2, 9).Value = (Val(Cells(3, 9).Value)) - (Val(Cells(2, 7).Value)) + (Val(Cells(2, 8).Value)) ' PREGUNTAR A RICARDO
End If
Sheets(CLASE).Select
filalibre = Range("A2").End(xlDown).Offset(1, 0).Row 'la variable filalibre guarda el nro. De la primer celda vacía.
dato = cuenta
rango = "A2:A" & filalibre
Set midato = ActiveSheet.Range(rango).Find(dato, LookIn:=xlValues, LookAt:=xlWhole)
If Not (midato) Is Nothing Then
    ubica = midato.Address(False, False)
    Range(ubica).Offset(0, 2).Value = Val(Range(ubica).Offset(0, 2).Value) + Val(debe) ' PREGUNTAR COMO SERIA EN CADA CASO
End If
Workbooks(Libro & ".xls").Save
Workbooks(Libro & ".xls").Close
End Function

1 Respuesta

Respuesta
1
Una forma sencilla de hacerlo, es agregar un parámetro más a tu procedimiento (en tu ejemplo, una función) de la siguiente forma
Public Function contabilizar_fact(cta, doc, debe, haber,campoTexto)
Resta, dentro de la función, poner la asignación
campoTexto.value = xxxx
Luego al lamar a la función, le entregas en ese parámetro, el cuadro de texto al que le quieras asignar el valor.
Ejemplo:
Contabilizar_fact 00,00,00,00,TextBox1
Hola gracias por tu respuesta..
Pero mira el problema es que cuando llamo el modulo de function y le doy tome la info del formulario TextBox109 ' NO DE documento y me lo ponga en una celda
Cells(2, 3).Value = TextBox109
No me toma nada. Entonces le pongo el nombre del formulario
Cells(2, 3). Value = FACTURACION.TextBox109
y ya lo toma y lo llena. Pero mi problema es que en este caso me sirve pero cuando tenga una cta de cobro
tendré que hacer
Cells(2, 3). Value = CTA_COBRO.TextBox109 y cuando sea recibo de caja Cells(2, 3). Value = RECIBO_CAJA.TextBox109
y así sucesivamente entonces ya el mismo modulo no me sirve para todos me toca hacer un modulo para cada proceso y eso es lo que quiero evitar
Vendría a ser casi lo mismo, lo que cambia es que, en lugar de prestarle el campo de texto mediante el parámetro, ahora le entregas el formulario, lo que quedaría algo así:
Public Function contabilizar_fact(cta, doc, debe, haber,frm)
'dentro de la función lo ocuparías así (ocupando tu ejemplo):
...
Cells(2, 3).Value = frm.TextBox109 ' NO DE documento
Cells(2, 4).Value = frm.TextBox37 ' nit a quien lo aplicamos
Cells(2, 5).Value = frm.TextBox38 ' nombre
Cells(2, 6).Value = frm.TextBox108 ' fEcha de aplicacion
...
End Sub
Y la lo podrías utilizar, dentro de cada formulario, de esta forma:
Contabilizar_fact 00,00,00,00,Me
Me: Referencia al propio formulario
Excelente
Muchas gracias
No se por que no me había funcionado ami. Pero como lo plateas esta perfecto
Había ya intentado antes poner variables a estas sentencias y no me había funcionado muchas gracias

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas