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

Posted on 2007-07-26
Last Modified: 2010-04-30

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

Question by:iaing1000
    LVL 22

    Accepted 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


    Author Comment


    Yes, that seems to work perfectly.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now