VBA Code Question

  • Thread starter Thread starter Theresa
  • Start date Start date
T

Theresa

Hello:

I have a macro that opens a specific file. I want the
macro to open any filename that I specify in a popup
box. Does anyone know how I can accomplish this?

Any help would be great.

Thanks
 
--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Theresa,

Something like

sName = Inputbox("Please supply filename")
Workbooks.Open Filename:=sName

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Theresa,

Try something like the following:

Dim FName As Variant
FName = Application.GetOpenFilename("Excel files (*.xls),*.xls")
If FName = False Then
' user clicked cancel
Else
Workbooks.Open FName
End If



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
Try this with GetOpenFilename

Sub testing()
Dim FName As Variant
Dim N As Long
Dim S As String
FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls", _
MultiSelect:=True)

If IsArray(FName) Then
For N = LBound(FName) To UBound(FName)
Workbooks.Open (FName(N))
Next
End If
End Sub
 
Chdrive "C"
ChDir "C:\My Folder"
fName = Application.GetOpenFilename()
if fName <> false then
workbooks.open fName
End Sub
 
Hi Theresa,

Try this code at the top of of your macro and it should allow you to
open up any file as it prompts you to select the file you want to use.
So just incase you don't remeber the name of the file. Excel will do an
open file function and you can pick the file you want.

myFile = Application.GetOpenFilename("Excel Files, *.xls")

Hope it works and good luck.

Oli
 
Back
Top