fileDialog answer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using the following code to get the file name and path, but after the
user click the file, Excel open it.
I don't want the Excel file to open, all I need is to get the file name that
the user selected from the FileDialog box to pass it to excel object:

With
xl.FileDialog(Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFilePicker)
..AllowMultiSelect = False
..Filters.Clear()
..Filters.Add("Excel Files", "*.xls;*.xlw;*.htm;*.html")
If .Show <> 0 Then fileName = .SelectedItems.Item(1)
End With
..... .... .. .
Dim wb As Excel.Workbook = xl.Workbooks.Open(fileName)
...... .... ... ..
do some operation on the file without displaying it to the user .....


how can I do ?

thanks
 
Hi

Based on my test ,the FileDialog will not open the file when we select file
in the filedialog and click OK or double click on the file.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim exApp As New Excel.ApplicationClass
exApp.Visible = True
Dim fileName As String
With
exApp.FileDialog(Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFilePi
cker)
.AllowMultiSelect = False
.Filters.Clear()
.Filters.Add("Excel Files", "*.xls;*.xlw;*.htm;*.html")
If .Show <> 0 Then fileName = .SelectedItems.Item(1)
End With
'Dim wb As Excel.Workbook = exApp.Workbooks.Open(fileName)
End Sub

I think this may be caused by the code line below, which will open the
workbook the fileName pointed to.
'Dim wb As Excel.Workbook = exApp.Workbooks.Open(fileName)

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top