I have the following code that is causing me the error "Object Variable or With block variable not set"
The code roughly what it does is: it opens a file, search for a word, when find cut and paste a range of cells in another file.
When he returns to find and not find the word I get an error, for which we add the instruction "On Error GoTo"
But it does not work, if someone could help me thank you.
regards
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
The code roughly what it does is: it opens a file, search for a word, when find cut and paste a range of cells in another file.
When he returns to find and not find the word I get an error, for which we add the instruction "On Error GoTo"
But it does not work, if someone could help me thank you.
regards
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