0
Public Sub EliminaPedido(Num As Integer, Hoja1 As Worksheet)

and at the main form:

Private Sub bBaja_Click()
    Dim x10 As New Excel.Application
    Dim ArchivoDestino As Workbook
    Dim R As String
    R = "Año " & Year(Now)
    Set ArchivoDestino = x10.Workbooks.Open(Ruta & "\Registro pedidos.xlsx", 0)
    Dim M As Integer
    M = MsgBox("Desea eliminar el pedido " & Me.Range("H2").Value & " emitido a " & Me.Range("E11").Value & "?", vbExclamation + vbYesNo, "Pedidos de Elementos")
    If M = 6 Then EliminaPedido Me.Range("H2").Value, ArchivoDestino.Worksheets(R)
    ArchivoDestino.Close True
End Sub

When EliminaPedido ends, the object Hoja1 is freed, or into that sub I must use set Hoja1 = Nothing?

GSerg
  • 76,472
  • 17
  • 159
  • 346
leo3487
  • 1
  • 2
  • 2
    The parameter Hoja1 will go out of scope at the end of the sub. There is nothing you need to do. Do not assign the value of nothing to Hoja1 as this could cause a memory leak. To understand why read up on the difference between passing parameters ByRef and ByVal. In the code you posted you have implicitly declared Hoja1 as ByRef as this is the default action for VBA. – freeflow Oct 16 '22 at 12:06
  • @freeflow `Do not assign the value of nothing to Hoja1 as this could cause a memory leak` - how? `read up on the difference between passing parameters ByRef and ByVal` - what difference does that make regarding the alleged memory leak? – GSerg Jun 02 '23 at 11:44

0 Answers0