Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Opening all linked workbooks
Hello,
I want to write a simple .NET Windows app that will open an Excel workbook, then open all workbooks that are linked to that workbook. How can I do this? I haven't yet found documentation or samples on this. Also, if anyone knows how to get the number of linked workbooks, that would be very helpful too, so I can display a progress bar. My source code so far is below. It works but is obviously missing the code to open all linked workbooks. Thank you so much! Eric //////////////////////////////////////////// // Code assumes .NET 2.0 using Excel = Microsoft.Office.Interop.Excel; using System.IO; using System.Reflection; // Code within OpenLinkedFiles method: try { string lastFile = GetLastUsedPath(); dlg.InitialDirectory = Path.GetPathRoot(lastFile); dlg.FileName = (File.GetAttributes(lastFile) == FileAttributes.Directory ? string.Empty : Path.GetFileName(lastFile)); dlg.Filter = "Excel files (*.xls)|*.xl*|All files (*.*)|*.*"; dlg.Title = "Select the master Excel file..."; } catch { } DialogResult result = dlg.ShowDialog(); if (result != DialogResult.Cancel) { try { // Save current file path to XML. SaveFilePath(dlg.FileName); // Open the parent workbook. object mv = Missing.Value; Excel.ApplicationClass excel; Excel.Workbooks workbooks; Excel.Workbook workbook; excel = new Excel.ApplicationClass(); excel.Visible = true; workbooks = excel.Workbooks; workbook = workbooks.Open(dlg.FileName, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv); // Open all child/linked workbooks. // ??? } catch (Exception ex) { MessageBox.Show("Error opening Excel files:\n\n" + ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } //////////////////////////////////////////// |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Linked workbooks | Excel Worksheet Functions | |||
auto updating & linking 2 workbooks without opening the linked | Excel Discussion (Misc queries) | |||
Linked workbooks | Excel Discussion (Misc queries) | |||
Opening Linked Workbooks from Summary | Excel Programming | |||
name changes to linked workbooks | Excel Discussion (Misc queries) |