Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/09/2013, 09:35
jongova
 
Fecha de Ingreso: septiembre-2013
Mensajes: 1
Antigüedad: 10 años, 8 meses
Puntos: 0
Sonrisa Como usar On Error GoTo

Tengo el siguiente codigo que me esta causando el error "Object variable or With block variable not set"

El codigo a grandes rasgos lo que hace es que abre un archivo, busca una palabra, cuando la encuentra corta y pega un rango de celdas en otro archivo.

Cuando vuelve a buscar y no encuentra la palabra me sale un error, para lo cual le agregue la instruccion de "On Error GoTo"

Pero no funciona, si alguien me podria ayudar se los agradezco.

Saludos
jongova


Sub AbrirBuscar()
'
'
Dim sPath As String, sName As String
Dim bk As Workbook
On Error GoTo CerrarArchivo
sPath = "D:\Documents\SQ\Licitaciones\2013 MegaLicitacion\TEST\"
sName = Dir(sPath & "*.xls")
Do While sName <> ""
Set bk = Workbooks.Open(sPath & sName)

Cells.Find(what:="BACAL-515 (DES)", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(-3, 0).Range(Cells(1, 1), Cells(62, 11)).Select
Selection.Cut
Windows("Book1").Activate
ActiveSheet.Paste
ActiveCell.Offset(62, 0).Activate
Workbooks(2).Activate


Cells.Find(what:="BACAL-515 (DES)", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(-3, 0).Range(Cells(1, 1), Cells(62, 11)).Select
Selection.Cut
Windows("Book1").Activate
ActiveSheet.Paste
ActiveCell.Offset(62, 0).Activate

CerrarArchivo:
bk.Close Savechanges:=False
sName = Dir()

Loop

End Sub