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.
  • Avatar do usuário
Avatar do usuário
Por GustavoFV
Avatar
#40139
Boa Tarde a todos,
Me passaram um problema que até então eu consegui descobrir mas não automatiza-la já na própria macro.
Abaixo esta o código da mesma:
Código: Selecionar todos
 
ActiveWorkbook.Queries.Add Name:="pd002r00", Formula:= _
        "let" & Chr(13) & "" & Chr(10) & "    Fonte = Table.FromColumns({Lines.FromBinary(File.Contents(""Z:\PCP\CTG\CRONOGRAMAS\ACESSRIOS\PEAS SOBRESSALENTES\Regulador\Relatrios\pd002r00.txt""), null, null, 1252)})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    Fonte"
            Dim Nome As String

ActiveWorkbook.Worksheets.Add
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
        "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=pd002r00;Extended Properties=""""" _
        , Destination:=Range("$A$1")).QueryTable
        .CommandType = xlCmdSql
        .CommandText = Array("SELECT * FROM [pd002r00]")
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .ListObject.DisplayName = "pd002r00"
        .Refresh BackgroundQuery:=False
    End With

 Application.CommandBars("Queries and Connections").Visible = True
O problema é o seguinte, este comando inicia um conexão com o "pd002" e imprimi as informações dele no Excel, mas ao rodar novamente a macro acontece o erro de que esta conexão já esta em uso. Mexendo um pouco descobri que esta conexão esta em "Queries and Connections" (ate incrementei o código para torna-la visível) e que é preciso exclui-la para a macro funcionar novamente.
Meu objetivo é excluir a conexão automaticamente para que o usuário não tenha que interagir no processo.
Poderiam me ajudar?
Desde já, Agradeço.
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