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")); }
/// <summary>Extracts VBA modules from current EXCEL workbook to a sibling directory.</summary> /// <param name="sender">The object that initiated the event.</param> /// <remarks> /// Requires that access to the VBA project object model be trusted (Macro Security). /// </remarks> private void ExportCurrent(object sender) { if (!IsProjectModelTrusted()) { return; } var exporter = new VbaSourceExporter(Application); exporter.StatusAvailable += StatusAvailable; try { Application.Cursor = XlMousePointer.xlWait; exporter.ExtractOpenProject(Application.ActiveWorkbook, DestIsSrc); } catch (IOException ex) { ex.Message.MsgBoxShow(CallerName()); } finally { Application.Cursor = XlMousePointer.xlDefault; exporter.StatusAvailable -= StatusAvailable; Application.StatusBar = "Ready"; } }