I'm working with two workbooks, both with different sheets. The code is writen for the Workbook called "Rober.xslm" and in the following macro I open another workbook ("Formato permisos.xlsm") and read values in some sheets to work with them in my original workbook. Firstly I managed to read the values from the sheet "Requisitos contenedor + ATI" in the workbook "Formato permisos.xlsm" and work with then in my sheet "Seleccion_ECs" from "Rober.xlsm".
The problem comes when I select, or activate, or open the sheet "ECs full" from the workbook "Rober.xlsm". I don't understand why this statement: Set shECF=wbDest.Worksheets("ECs full") returns Nothing if I also have this one: Set shrelacion=wbDest.Worksheets("Relación ciclo y fechas") and it works with it! The name ECs full is well written. It's a normal sheet, not a chartsheet.
Set wbSource = Workbooks.Open(sFileName)
Debug.Print (wbSource.Name) '"Formato permisos.xlsm"
If Err.Number <> 0 Then Debug.Print ("Error number en Libro gráficas: " & Err.Number)
If Err.Number = 0 Then Debug.Print ("No ha habido error en libro gráficas")
Set Requisitos = wbSource.Worksheets("Requisitos Contenedor + ATI")
Set QvsE = Workbooks.Open(sFileName) 'wbSource.Charts("Curva - QvsE")
Set wbDest = ThisWorkbook 'Workbooks("Rober.xlsm")
Debug.Print (wbDest.Name) '"Rober.xlsm"
If Err.Number <> 0 Then Debug.Print ("Error number en Libro Rober: " & Err.Number)
Set shEC = wbDest.Worksheets("Seleccion_ECs")
If Err.Number <> 0 Then Debug.Print ("Error number en hoja Seleccion_ECs: " & Err.Number)
im fechaActual As Variant, fechaEOC As Date
Dim shECF As Worksheets, rangoECF As Range
Dim nFilasECF As Double, nColumECF As Double, años As Double
Set shECF = wbDest.Worksheets("ECs full")
'wbDest.Sheets("ECs_full").Activate --These are some thigs I tried
'wbDest.Sheets("ECs_full").Select
If Err.Number <> 0 Then Debug.Print ("Error al seleccionar hoja ECs full: " & Err.Number)
MsgBox ThisWorkbook.Path & vbNewLine & ThisWorkbook.Name 'Archivo Rober
Set rangoECF = Sheets("ECs full").UsedRange
nFilasECF = rangoECF.Rows.Count
nColumECF = rangoECF.Columns.Count
Set shrelacion = wbDest.Worksheets("Relación ciclo y fechas")
For g = 1 To nColumECF
If shECF.Cells(1, g) = "último ciclo de operación" Then
C = shECF.Cells(1, g).Column 'Don't manage to get this value since I can't read the sheet "ECs full"
End If
Next g