vb problem

Associate
Joined
8 Jul 2007
Posts
321
Location
Reading
I've been playing around with vb lately, but am stumped at this problem.

fileToOpen = Application _
.GetOpenFilename("Excel Files (*.xls), *.xls")
Sheets("SCANNED").Select
Workbooks.Open Filename:="C:\Documents and settings\acoop\Desktop\report.xls" _
, Origin:=xlWindows

I want it to open an open file box, then you select an excel file and it imports the data. The problem is it is trying to select it from that C:: location, I want the location to be user specified. How do I do this?
 
I've been playing around with vb lately, but am stumped at this problem.

fileToOpen = Application _
.GetOpenFilename("Excel Files (*.xls), *.xls")
Sheets("SCANNED").Select
Workbooks.Open Filename:="C:\Documents and settings\acoop\Desktop\report.xls" _
, Origin:=xlWindows

I want it to open an open file box, then you select an excel file and it imports the data. The problem is it is trying to select it from that C:: location, I want the location to be user specified. How do I do this?


Code:
[B][I]Private ofd As OpenFileDialog = New OpenFileDialog()
Private ofd .Title = "Browse"
Private ofd .InitialDirectory = "c:\"
If ofd .ShowDialog() = DialogResult.OK Then[/I][/B]

fileToOpen = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
    Sheets("SCANNED").Select
    Workbooks.Open Filename:=[I][B]ofd .FileName[/B][/I], Origin:=xlWindows
[B][I]End If[/I][/B]

Give that a try. (Untested, but its close)
 
Back
Top Bottom