Get textfile Name

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
I have a text file that is always in a 16 digit alpha-numeric format ####-####-####-####.
How can I get this file name and insert it in a userform label?
 
As long as only one of the files is 23 characters long, how about
Rich (BB code):
   Dim Pth As String, Fname As String
   
   Pth = "C:\Mrexcel\Textfiles\"
   Fname = Dir(Pth & "*.txt")
   Do While Fname <> ""
      If Len(Fname) = 23 Then Exit Do
      Fname = Dir
   Loop
   Me.Label1.Caption = Fname
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Upvote 0
One more question ... is the other text file always older than the daily imported file ?
 
Upvote 0
The TmEvnt will be used each time the workbook is opened. The other will used sparelingly.
 
Upvote 0
.
Ok ... see if this does the job for you :

VBA Code:
Private Sub UserForm_Initialize()
Dim fc  As Integer
Dim fldr As FileDialog
Dim getfolder As String
Dim wrd As Variant, strfile As Variant
    
    getfolder = "C:\Users\gagli\Desktop\Beta"
    Set fldr = Nothing
      
    strfile = Dir(getfolder & "\*" & ".txt" & "*")
    If strfile <> "TmEvnt.txt" Then
    Me.Label1.Caption = strfile
    End If

End Sub

Fluff ... thank you for contributing.
 
Upvote 0
My apologies guys....it was late where I live. Fluff & Logit....Thank you both for your help. I used post 11 code.
Is it possible to not include the extension? I greatly appreciate it.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top