Open .xls with viewer

Posted on 2006-04-05
Last Modified: 2008-01-09
I have a program that will open .xls files with the full version of excel. How can i get it to open the fiels with excel viewer. This is with Visual Basic 6
Question by:Kirius
    LVL 28

    Expert Comment

    if you goto Project > Components you can add the Microsoft Internet Controls which will give you the Webbrowser control. If you add that control you can view excel files using something like this:

    Private Sub Command1_Click()
    WebBrowser1.Navigate2 "C:\Test.xls"
    End Sub
    LVL 1

    Author Comment

    Well what I have is a program where you can choose what .xls you want to view. Each .xls has about 10-50 sheets in it. I can open it fine on workstations with full versions of office. But some workstations, I don't want to use Internet Explorer or Full version excel because they don't have it on those. But to open it with Excel Viewer.
    LVL 28

    Accepted Solution

    if you are using shellexecute api it will launch xls files with the default app which would be the full version of excel if it exists. To launch the viewer you will need to have it's location:

    Private Sub Command1_Click()
    Dim ExcelFile as String
    ExcelFile =  Chr(34) & "C:\Test.xls" & Chr(34)

    Shell Chr(34) & "C:\Program Files\Microsoft Office\OFFICE11\XLVIEW.EXE" & Chr(34) & " " & ExcelFile, vbNormalFocus

    End Sub

    Expert Comment

    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 Command1_Click()
    Dim xlsPath, xlsVwr As String
    Dim retVal As Long

    'Path of excelviewer can be extracted out of the registry.
    '@="C:\\PROGRA~1\\MICROS~3\\OFFICE11\\XLVIEW.EXE /e"

    'Path of the XLS File
    xlsPath = App.Path & "\map1.xls"

    'Run the Viewer
    retVal = ShellExecute(Me.hwnd, "Open", xlsVwr, xlsPath, "", 1)

    End Sub

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    sameEnds challenge 25 56
    EvenOdd challenge 10 68
    thread-safe code in c++ 2 58
    find a node in VST 2 36
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    This article will show, step by step, how to integrate R code into a R Sweave document
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    731 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

    15 Experts available now in Live!

    Get 1:1 Help Now