E
Eric
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);
}
}
////////////////////////////////////////////
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);
}
}
////////////////////////////////////////////