我正在編寫一個代碼,其中我正在打開一個用於提取數據的文件。我目前使用下面的代碼;我想從路徑中提取文件名並將其存儲在特定範圍內。此代碼:如何從其路徑中提取文件名vba
FilePath = Application.GetOpenFilename("Excel Files (*.xlsx), *.xls")
If FilePath <> False Then
Range("D6").Value = FilePath
file = Range("D6").Value
Range("D6").Clear
End If
你說「我想要從路徑中提取文件名並將其存儲在特定範圍內「你清除D6。那麼你想在後面的代碼中使用'file = Range(「D6).value'做些什麼**並且**你希望D6只有文件名而沒有它的路徑? –
是的,我使用了它並且它工作得很好 strName = Right(FilePath,Len(FilePath) - InStrRev(FilePath,「\」)) 然後我將strName指定給Range並使用相同的值 – Ansh