Click here to Skip to main content
15,914,221 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
my application saves an array as as excel sheet in d drive:
the code is:
xlWorkSheet.SaveAs("D:\vbexcel.xlsx")


how can i give a "save as" option to user so that the user can save the file in any location.?
Posted

1 solution

Use the SaveFileDialog:

VB
Private Sub myButton_Click(sender As Object, e As EventArgs)
        Dim myStream As Stream
        Dim saveFileDialog As New SaveFileDialog()

        saveFileDialog.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*"
        saveFileDialog.FilterIndex = 2
        saveFileDialog.RestoreDirectory = True

        If saveFileDialog.ShowDialog() = DialogResult.OK Then
            xlWorkSheet.SaveAs(saveFileDialog.Filename)
        End If
End Sub


Hope this helps,
Fredrik
 
Share this answer
 
Comments
Ankur\m/ 30-Jul-13 4:17am    
Correct, 5!
Fredrik Bornander 30-Jul-13 16:43pm    
Thanks man!
hlsc1983 30-Jul-13 7:54am    
can anyone explain the need for declaring myStream as Stream datatype. i commented that line and still the application works......please shed some light. thanks..
Fredrik Bornander 30-Jul-13 8:34am    
No need, it's in there by mistake. You should not include it in your code.
hlsc1983 30-Jul-13 8:49am    
thank you..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900