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.
#70944
Olá. Pessoal preciso de uma orientação e ajuda. Já pesquisei na internet de tudo que é jeito. Eu fiz o código e ele está funcional para mim. Porém, ele só seleciona um arquivo TXT da pasta. Tenho diversos arquivos e queria usar a pesquisa e p multiselect para selecionar apenas os que eu preciso. Não consigo de jeito algum fazer funcionar. Toda vez que tento pelo multiselect ele dá o erro 1004.

Código: Selecionar todos
Option Explicit

Sub ImportarTXT()
    Dim FilePath As String
    Dim WorksheetName As String
    Dim ws As Worksheet
    Dim FileNameParts() As String
   
    FilePath = BrowseFilePath("Arquivos do Text,*.txt", "Selecione os arquivos", True)
    If FilePath = "" Then Exit Sub
    
        Set ws = ActiveSheet
        ws.Cells.Delete
        With ws.QueryTables.Add(Connection:="TEXT;" & FilePath, _
                Destination:=Range("A1"))
                .TextFileTabDelimiter = True
                .Refresh BackgroundQuery:=False
                .Delete
        End With
            
        FileNameParts = Split(FilePath, "\")
        WorksheetName = FileNameParts(UBound(FileNameParts))
        WorksheetName = Left(WorksheetName, InStrRev(WorksheetName, ".") - 1)
        ws.Name = WorksheetName
End Sub

Private Function BrowseFilePath(pFileFilter As String, pTitle As String, Multiselect) As String
    Dim FilePath As String
    
    
    FilePath = CStr(Application.GetOpenFilename(FileFilter:=pFileFilter, Title:=pTitle, Multiselect:=True))
    If FilePath = CStr(False) Then GoTo Quit

    BrowseFilePath = FilePath
    
Quit:
End Function
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