Macro to choose file and add name to a cell

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
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
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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
 
Upvote 0
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:
Upvote 0
Good job Tony. To get filename only use:
Code:
Dir$(.SelectedItems(1))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,112
Members
453,021
Latest member
Justyna P

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