protected ILinksAnalysis ExtendFromWorkbookList(Range range) { if (range == null) { return(null); } StatusAvailable?.Invoke(this, new EventArgs <string>("Loading background processor ...")); var nameList = range.GetNameList(); using (var newExcel = WorkbookProcessor.New(range.Application, true)) { foreach (var item in nameList) { if (item is string path) { if (!File.Exists(path)) { AddFileAccessError(path, "File not found."); continue; } StatusAvailable?.Invoke(this, new EventArgs <string>($"Processing {path} ...")); try { newExcel.DoOnWorkbook(item, wb => ExtendFromWorkbook(wb)); } catch (IOException ex) { AddFileAccessError(path, $"IOException: '{ex.Message}'"); } finally { StatusAvailable?.Invoke(this, new EventArgs <string>("Ready")); } } } } return(this); }
private void ExportSelected(object sender) { if (!IsProjectModelTrusted()) { return; } var fd = Application.FileDialog[MsoFileDialogType.msoFileDialogFilePicker]; fd.Title = "Select VBA Project(s) to Export From"; fd.ButtonName = "Export"; fd.AllowMultiSelect = true; fd.Filters.Clear(); fd.InitialFileName = Application.ActiveWorkbook?.Path ?? "C:\\"; Application.Cursor = XlMousePointer.xlWait; StatusAvailable(this, new EventArgs <string>("Loading background processor ...")); using (var processor = WorkbookProcessor.New(Application, true)) { var list = VbaSourceExporter.FillFilters(processor, fd); Application.Cursor = XlMousePointer.xlDefault; if (fd.Show() != 0) { Application.Cursor = XlMousePointer.xlWait; try { var exporter = new VbaSourceExporter(Application); exporter.StatusAvailable += StatusAvailable; exporter.ExportSelected(list[fd.FilterIndex - 1], fd.SelectedItems, DestIsSrc); exporter.StatusAvailable -= StatusAvailable; } catch (IOException ex) { ex.Message.MsgBoxShow(CallerName()); } finally { Application.Cursor = XlMousePointer.xlDefault; } } } #if DEBUG Application.Cursor = XlMousePointer.xlWait; GC.Collect(); GC.WaitForPendingFinalizers(); Application.Cursor = XlMousePointer.xlDefault; #endif StatusAvailable(this, new EventArgs <string>("Ready")); }