When I tried to open an excel file from my macro: I have a 1004 problem, and if I debug the code and press F5 to continue the file is opened without any problem, also If I debug the code line by line works.
Sub openFile2(ruta, fich, destino As Worksheet)
Application.CutCopyMode = False
Dim aux As String
aux = ruta & "\" & fich
ChDir ruta
Workbooks.Open Filename:=fich
End Sub
My values
Ruta
"C:\Users\Usuario\Desktop\Swap\@&&Informes&&@\Informes 2G\Input"
fich
"CNA_GsmRel_Z2_23052013.xls"
Also i tried with:
aux = ruta & "\" & fich
Workbooks.Open Filename:=aux
Workbooks.Open
requires the complete pathFilename
so it should beWorkbooks.Open(FileName:=aux)
instead ofWorkbooks.Open(FileName:=fich)
Declaring workbook variable
wkb
gives you control over the workbook for further manipulation.Save the workbook which houses the code before running the code.
Use below code which is more robust.