Advertisement
Nihad

VBA Code: Get File Name and Path in Directory

Dec 10th, 2024
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VisualBasic 0.53 KB | Source Code | 0 0
  1. Sub MorshedDhaka()
  2.    Dim Fldr As String, Fname As String
  3.    Dim ObjFldr As Object
  4.    Dim i As Long
  5.    
  6.    Set ObjFldr = Application.FileDialog(4)
  7.    With ObjFldr
  8.       .Title = "Choose a folder"
  9.       .AllowMultiSelect = False
  10.       If .Show = -1 Then Fldr = .SelectedItems(1)
  11.    End With
  12.    If Fldr = "" Then Exit Sub
  13.    Fname = Dir(Fldr & "\*")
  14.    Do While Fname <> ""
  15.       i = i + 1
  16.       Cells(i, 1) = Left(Fname, InStrRev(Fname, ".") - 1)
  17.       Cells(i, 2) = Fldr & "\" & Fname
  18.       Fname = Dir()
  19.    Loop
  20. End Sub
  21.  
Tags: vba
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement