Hello clever people,

Completely new to VB.NET (only installed Visual Studio 2019 in the past couple of days).

To start all I want to do is open Excel (office 365) from a button on a userform. The location of the file is on a network, lets say: -

\file-svr01\Rozel\Design\Parts\PNG.xlsx
OR
R:\Design\Parts\PNG.xlsx

I don't need to read in any information from the spread sheet, just open it so thgat i can edit it.

Please bear in mind I am completely new to VB.NET, so if I have to initialise anything in the code before trying to open excel, it would be good if you can put this in any possible solutions.

I have tried using google, I've gone through lots of different web sites and tried lots of things and nothing works, but mainly because I don't really understand the syntax

Can anyone help?

Thanks.

You can do this:

Process.Start("EXCEL.EXE", """R:\Design\Parts\PNG.xlsx""")

Documentation:

MSDN

Thanks for the advice, This is the code I have

    If File.Exists("R:\Design\Parts\PNG.xlsx") Then
        Process.Start("EXCEL.EXE", """R:\Design\Parts\PNG.xlsx""")
    End If

Executing the code, the if statement works because it steps into the process.start, but i get the following message, which I haven't a clue how to solve.

System.ComponentModel.Win32Exception: 'The system cannot find the file specified.'

The file is in the correct location as i can open it by coping the "R:\Design\Parts\PNG.xlsx" and pasting it into windows explorer.

Perhaps the double double quotes are causing this, try:

Process.Start("EXCEL.EXE", "R:\Design\Parts\PNG.xlsx")

Or, excel.exe is not in your path, try specifying the full path.

Thank you for your help, changing to the following works.

Process.Start("C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE", """R:\Design\Parts\PNG.xlsx""")

So, you win the 'Man of the Day' award for your help by offering a simple line of code and helping when it didn't work.

I see it's been a while since you posted, but I'm curious if anyone here has tried using the Open XML SDK instead of Interop or OleDb for reading Excel files. I found it faster and doesn't require Excel to be installed, though it can be more complex for writing. Wondering how others handle big Excel files or ones with tricky formatting?

I've worked on something similar and found that using Microsoft.Office.Interop.Excel lets you open the file and loop through cells easily.

A Microsoft Excel document can be opened in VB.NET using the Microsoft.Office.Interop.Excel library. Using Workbooks.Open(), open the workbook, and then display the Excel window. Reference the Excel COM object in your project.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.