我正在使用两个工作簿,每个工作簿都有不同的工作表。该代码是为名为“ Rober.xslm”的工作簿编写的,在下面的宏中,我打开另一个工作簿(“ Formato permisos.xlsm”),并读取某些工作表中的值以在我的原始工作簿中使用它们。首先,我设法从工作簿“ Formato permisos.xlsm”的工作表“ Requisitos contenedor + ATI”中读取值,然后在“ Rober.xlsm”的工作表“ Seleccion_ECs”中进行处理。
当我从工作簿“ Rober.xlsm”中选择或激活或打开工作表“ ECs full”时,就会出现问题。我不明白为什么这样说: 设置shECF = wbDest.Worksheets(“ EC已满”) 如果我也有此内容,则不返回任何内容: 设置shrelacion = wbDest.Worksheets(“Relaciónciclo y fechas”) 它可以工作! EC full的名称写得很好。这是正常的工作表,而不是图表。
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
答案 0 :(得分:1)
我花了一段时间才能看到这个
Dim shECF As Worksheet
(不是工作表 s )