I have the following macro code:
Dim Cenarios As Integer
Worksheets(Interface.Name).Activate
Call Ultima_Linha
Cenarios = UL - 1 'Desconta a linha de cabeçalho
'Armazena o caminho dos cenários a serem comparados
Dim Cen_index As Variant
Dim Cen_caminho As Variant
Dim Ind As Integer
'Dimensiona os arrays de dados
'Todos os arrays estão em base 0
ReDim Cen_index(0 To Cenarios - 1)
ReDim Cen_caminho(0 To Cenarios - 1)
For Ind = 0 To Cenarios - 1
Cen_index(Ind) = Cells(2 + Ind, 1)
Cen_caminho(Ind) = Cells(2 + Ind, 2)
Next Ind
'Provedor da conexão para consulta
Dim Provedor As String
Provedor = "Microsoft.ACE.OLEDB.12.0" 'String de parâmetros de conexão
'Definição das variáveis
Dim Caminho As String
Dim Indi_cen As Integer
Dim Resultados As Variant
Dim Headers As Variant
Dim Dados_Orig As Variant
Dim Dados As Variant
'Limites de Arcos
'Limpa e seleciona a planilha de destino
Worksheets("Arcos").Cells.Clear
Worksheets("Arcos").Activate
For the sheet "Interface" I was able to use the Worksheets(sheet.name)
reference, but for other sheets, like "Arcos" I could not. I had to use the Worksheets("sheet name")
reference.
What can cause this kind of behaviour?
Why I could use only once the reference directly through the sheet's name? Using the later one makes the code prone to errors since the user can alter the name of the sheet and the code will crash.
VBA reports the runtime error 424 object required when I try to use for the second time the worksheets(sheet.name)
reference, I mean instead of using worksheets("Arcos").Activate
I would like to use Worksheets(Arcos.Name).Activate
.