Meu código solicita que o usuário selecione um arquivo. Quero definir uma variável para o nome da pasta do local do arquivo, mas o arquivo está localizado em uma subpasta.
Eu tenho esse código para abrir o arquivo.
fileAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.csv), _
*.csv", Title:="Select a file")
If fileAndPath = False Then Exit Sub
Este é o caminho de arquivo C: \ Store Location \ Employees \ Contact Information \ Phone Numbers \ 11373
Eu quero extrair a parte 11373 e armazená-la como uma variável
Ok, então você deseja definir uma pasta padrão para getOpenFileName. Preceda getOpenFileName com ChDir "D:\Test"
. Se a unidade for diferente de C: então preceda ChDir com ChDrive "DriveLetter:"
Sub test()
ChDrive "D:"
Application.DefaultFilePath = "D:\Test"
fileAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.csv),*.csv", Title:="Select a file")
If fileAndPath = False Then
Exit Sub
End If
folderPath = Left(fileAndPath, InStrRev(fileAndPath, "\") - 1)
MsgBox (Mid(folderPath, InStrRev(folderPath, "\") + 1))
End Sub
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras