0
Good afternoon,
Guys, I need a function in VBA that I can select a file and write the file name and its path in two cells. The file path I got, according to the code below. But the file name no, can anyone help me? For example: Cell B2 = C:User/Documents/Sales.xlsx Cell C2= Sales
Public Function AbrirArquivo() As String
    Dim Filtro As String
    Dim Titulo_da_Caixa As String
    Dim Arquivo As Variant
    Filtro = "Todos os Arquivos (*.*),"
    Titulo_da_Caixa = "Selecione o arquivo"
    ChDrive ("C")
    ChDir ("C:\")
    With Application
        Filename = .GetOpenFilename(Filtro, 3, Titulo_da_Caixa)
        ChDrive (Left(.DefaultFilePath, 1))
        ChDir (.DefaultFilePath)
    End With
    If Filename = False Then
        MsgBox "Nenhum arquivo foi selecionado."
        Exit Function
    End If
    AbrirArquivo = Filename
    Planilha2.Range("B2") = AbrirArquivo
End Function
From now on, thank you!