Macro to choose file and add name to a cell

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,350
Hi Everyone,

I would like a macro that when run brings up the folder window like the save as window and asks me to select which AMF file i want to use?
I can then select a file from my computer and the name i selected get input into cell G10

Please help if you can

Thanks

Tony
 

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,685
Office Version
365
Platform
Windows
Hi Tony

I don't know what an AMF file is but I am assuming it has amf extension (see filter in code below). The cod will display selected file name in message box but you can write it to a cell instead.

Code:
Sub GetFile()
    With Application.FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = False
        Call .Filters.Clear
        Call .Filters.Add("AMF Files", "*.amf")
        If .Show <> 0 Then
            MsgBox .SelectedItems(1)
        End If
    End With
End Sub
 

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,350
Hi Jon von der Heydon,
thank you for your help, sorry AMF is the type of template I used so the files are xlsx
but I got your code working ok and thanks for your help.
the problem is it gave me the whole filepath "C:\Users\tony\OneDrive\Desktop\Test1\AMF Justice Report - Jun 18 to May 19.xlsx" I need the cell to just contain the name "
AMF Justice Report - Jun 18 to May 19"
how can I get it to do this?
 
Last edited:

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,685
Office Version
365
Platform
Windows
Good job Tony. To get filename only use:
Code:
Dir$(.SelectedItems(1))
 
Last edited:

Forum statistics

Threads
1,077,993
Messages
5,337,602
Members
399,156
Latest member
RaudMees

Some videos you may like

This Week's Hot Topics

Top