• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 141
  • Last Modified:

Need to open a .csv file from code without assuming the use of Excel


I need to be able to open a .csv file from code.

In fact, what exactly needs to happen is that the the .csv file is opened in such a way as to mimic the double-clicking of the file from Windows Explorer when it may by default open Excel if it is on the PC or otherwise Notepad etc...... You see, many of the machines on which this software is running may not contain Excel, and even if they do, the user may expect .csv files to open in another app to which they associate .csv files.

This is a return to an old app out in the field using VB6. Is what I'm trying to do possible?

All and any help appreciated

1 Solution
If I understand you correctly, you just want to open a file in the associated application? Try the ShellExecute API:

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub Form_Load()
    ShellExecute 0, "Open", "c:\file.csv", 0, 0, 1
End Sub

iaing1000Author Commented:

Yes, that seems to work perfectly.


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now