Galera boa tarde.
Quem pode me ajudar?
Montei o código abaixo para atualizar a base de dados de uma tabela dinâmica, porem preciso que no nome do arquivo seja carregado o nome da varial "nomeplanilha"
Sub teste()
Dim Ultima_linha As String
Sheets("Base").Select
Range("a1").Select
Selection.End(xlDown).Select
Selection.End(xlToRight).Select
Ultima_linha = Mid(ActiveCell.AddressLocal, 4, 6)
Sheets("Diário").Select
Range("AE4") = Ultima_linha
ActiveSheet.PivotTables("Tabela dinâmica1").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"D:\Users\mtztassiolima\Videos\[FILIAL 0001.xlsm]Base!R1C1:R" & Ultima_linha & "c15", Version _
:=xlPivotTableVersion14)
End Sub
Quando tento criar a variavel e substituir pela [FILIAL 0001.xlsm] nao encontra o arquivo, porem eu ja verifiquei e ele traz o nome igualzinho como tá FILIAL 0001.slxm
nomeplanilha = ActiveWorkbook.Name
ActiveSheet.PivotTables("Tabela dinâmica1").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"D:\Users\mtztassiolima\Videos\[nomeplanilha] Base!R1C1:R" & Ultima_linha & "c15", Version _
:=xlPivotTableVersion14)