Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
#60609
Oi,

Preciso de ajuda para capturar informações de um arquivo .xls que é atualizado todos os dias em um site.

As informações que preciso estão no link https://www.anbima.com.br/informacoes/i ... adores.xls

Eu gravei uma macro pra colar essas informações em outra planilha que tenho, e ela funciona normal no primeiro dia
Código: Selecionar todos
Sub Anbima()

    ActiveWorkbook.Queries.Add Name:="INDICADORES_20201117_09_35#XLS", Formula _
        := _
        "let" & Chr(13) & "" & Chr(10) & "    Source = Excel.Workbook(Web.Contents(""https://www.anbima.com.br/informacoes/indicadores/arqs/indicadores.xls""), null, true)," & Chr(13) & "" & Chr(10) & "    #""INDICADORES_20201117_09_35#XLS1"" = Source{[Name=""INDICADORES_20201117_09_35#XLS""]}[Data]," & Chr(13) & "" & Chr(10) & "    #""Changed Type"" = Table.TransformColumnTypes(#""INDICADORES_20201117_09_35#XLS1"",{{""Column1"", type text}, {""Column2"", t" & _
        "ype text}, {""Column3"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Changed Type"""
    'ActiveWorkbook.Worksheets.Add
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
        "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=INDICADORES_20201117_09_35#XLS;Extended Properties=""""" _
        , Destination:=Range("$A$1")).QueryTable
        .CommandType = xlCmdSql
        .CommandText = Array("SELECT * FROM [INDICADORES_20201117_09_35#XLS]")
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .ListObject.DisplayName = "INDICADORES_20201117_09_35_XLS"
        .Refresh BackgroundQuery:=False
    End With
End Sub
O problema é que o nome da aba (a única da planilha) muda diariamente. No exemplo acima, o nome da aba é "INDICADORES_20201117_09_35_XLS", ou seja, ela foi atualizada no dia 17/11/2020 às 9:35. Mexer no '20201117' é tranquilo pra mim, mas não sei como lidar com o '09_35', já que a planilha não é atualizada sempre no mesmo horário. No dia 04/11/2020, por exemplo, a planilha foi atualizada às 09:39, e portanto o nome da aba era "INDICADORES_20201104_09_39_XLS".

Pergunta:


Como posso reescrever o código acima para conseguir capturar as informações da planilha sem precisar definir um nome para a aba?

Uma outra alternativa seria pegar os dados diretamente desse link: https://www.anbima.com.br/informacoes/indicadores/ , o problema é que o Excel não consegue reconhecer a tabela como sendo uma tabela, então não consigo fazer a conexão.
Você não está autorizado a ver ou baixar esse anexo.
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord