locked
Very basic question RRS feed

  • Question

  • I know this may sound stupid but I have to ask this question.

    How do I open an existing workbook that is in the default forlder.

    I can call Close() on workbook or Save(). But I do not see a method like Open("myWorkbook.xls").

    Oh btw, I am working on an Excel AddIn (VS2005, VSTO2005SE, Office2007)

    Khalique

    Friday, July 25, 2008 6:39 PM

Answers

  •  

    Hello Khalique,

     

    must be something like this:

     

    Code Snippet

    private Excel.Workbook OpenWorkbook(string filename) {

    bool readOnly = false;

    bool updateLinks = false;

    Excel.XlFileFormat format = Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel12;

    string password = null;

    bool writeResPassword = false;

    bool ignoreReadOnlyRecommended = false;

    object origin = null;

    string delimiter = null;

    bool editable = true;

    bool notify = false;

    object converter = Missing.Value ;

    bool addToMru = false;

    object local = Missing.Value;

    bool corruptLoad = false;

    Excel.Workbook workBook = Globals.ThisAddIn.Application.Workbooks.Open(filename

    , updateLinks

    , readOnly

    , format

    , password

    , writeResPassword

    , ignoreReadOnlyRecommended

    , origin

    , delimiter

    , editable

    , notify

    , converter

    , addToMru

    , local

    , corruptLoad);

    return workBook;

    }

     

     

    Hope this helps,

    greets, Helmut

    Saturday, July 26, 2008 9:59 PM
    Answerer

All replies

  •  

    Hello Khalique,

     

    you can get the default folders from registry or from environment or from the Applcation object.

     

    e.g.

    http://www.developingfor.net/vista/windows-special-folders.html

     

    Hope this helps,

    greets, Helmut

    Saturday, July 26, 2008 7:31 AM
    Answerer
  • Hi Helmut,

    Thanks for your reply.

    However, I wanted to know something else. I am asking how to Open a workbook that exists on disk. I know I can call Workbook.Save() to save a workbook but I am unable to discover how to achieve something like Workbook.Open() ( I know this method does not exists, it is just to make my point clear ). I want to make this call in my Excel AddIn code.

     

    TIA

    Khalique

    Saturday, July 26, 2008 12:12 PM
  •  

    Hello Khalique,

     

    must be something like this:

     

    Code Snippet

    private Excel.Workbook OpenWorkbook(string filename) {

    bool readOnly = false;

    bool updateLinks = false;

    Excel.XlFileFormat format = Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel12;

    string password = null;

    bool writeResPassword = false;

    bool ignoreReadOnlyRecommended = false;

    object origin = null;

    string delimiter = null;

    bool editable = true;

    bool notify = false;

    object converter = Missing.Value ;

    bool addToMru = false;

    object local = Missing.Value;

    bool corruptLoad = false;

    Excel.Workbook workBook = Globals.ThisAddIn.Application.Workbooks.Open(filename

    , updateLinks

    , readOnly

    , format

    , password

    , writeResPassword

    , ignoreReadOnlyRecommended

    , origin

    , delimiter

    , editable

    , notify

    , converter

    , addToMru

    , local

    , corruptLoad);

    return workBook;

    }

     

     

    Hope this helps,

    greets, Helmut

    Saturday, July 26, 2008 9:59 PM
    Answerer
  • Thanks Helmut. This is exactly what I was looking for and could not find in the documentation.

    Khalique

     

    Friday, August 1, 2008 8:59 PM