Macro to choose file and add name to a cell

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,353
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,353
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,078,500
Messages
5,340,743
Members
399,393
Latest member
farlow

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top