Import filename of .GetOpenFilename into specific sheet/cell

Koosbie

New Member
Joined
Oct 31, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hey! I'm pretty new to VBA, but I just need to add a code to import the filename of the selected file into A1 of sheet2. Here's what I have currently;

Sub ImportData()
Dim FileLocation As String

FileLocation = Application.GetOpenFilename
If FileLocation = "False" Then
Beep
Exit Sub
End If

Application.ScreenUpdating = False
Set ImportWorkbook = Workbooks.Open(Filename:=FileLocation)

ImportWorkbook.Worksheets(1).Range("A1:Z1000").Copy ThisWorkbook.Worksheets(1).Range("A1")

ImportWorkbook.Close
Application.ScreenUpdating = True

Application.ScreenUpdating = True

Worksheets("Scan sheet").Activate
Worksheets("Scan sheet").Select

Worksheets("Input data").Visible = xlSheetHidden
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Sheets(2).Range("A1").Value = FileLocation
Thanks for the quick reply!

I tried literally copy/paste that line and did not work, I also tried this and did not work.... :(

Worksheets("Scan sheet").Range("A1").Value = FileLocation
 
Upvote 0
if FileLocation have a value? its too simple not to work.
:ROFLMAO: The FileLocation value would be the file thats selected, then automatically closed onces its data is imported. Ive tried the code in the VBA before the file is closed and its not working.. like i said, your talking to a rookie here hahaha
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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