Code to open file

yamadk

New Member
Joined
May 19, 2011
Messages
4
Hi Everyone,

the below could does direct me to the file, but when I click on the file, it does not open it? any ideas?

Option Explicit
Sub GetImportFileName()
Dim Filt As String
Dim FilterIndex As Integer
Dim FileName As Variant
Dim Title As String

' Set up list of file filters
Filt = "All Files (*.*),*.*"
' Display *.* by default
FilterIndex = 5
' Set the dialog box caption
Title = "Select a File to Import"
' Get the file name
FileName = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Title)
' Exit if dialog box canceled
If FileName = False Then
MsgBox "Attention: No file was selected."
Exit Sub
End If

End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
GetOpenFileName doesn't actually open the file, it just gives a string referring to the chosen file. To open it you need:

Code:
Workbooks.Open FileName:=FileName
 
Upvote 0
GetOpenFileName doesn't actually open the file, it just gives a string referring to the chosen file. To open it you need:

Code:
Workbooks.Open FileName:=FileName

Hi Jon,

Thanks, i tried but, doesn't work. could you please post the the complete code.

Many thanks.
 
Upvote 0
That statement is for opening an Excel workbook. What type of file are you trying to open?
 
Upvote 0
And you put that line... where? After the End If and before the End Sub?
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,823
Members
452,946
Latest member
JoseDavid

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