Skip to content

Commit ee25947

Browse files
committed
[Fix] Excel crashes when opening the process waiting dialog.
1 parent fc7ff4b commit ee25947

2 files changed

Lines changed: 24 additions & 20 deletions

File tree

ImageInserter/Ribbon_imageInserter.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private void print(
1919
[System.Runtime.CompilerServices.CallerLineNumber] int line = 0
2020
)
2121
{
22-
System.Diagnostics.Trace.WriteLine($"{System.IO.Path.GetFileName(path), 15} (L:{line, 4}) | {function, -20} | {message}");
22+
System.Diagnostics.Trace.WriteLine($"{System.IO.Path.GetFileName(path),15} (L:{line,4}) | {function,-20} | {message}");
2323
}
2424
private void Ribbon_imageInserter_Load(object sender, RibbonUIEventArgs e)
2525
{
@@ -60,7 +60,7 @@ private void loadSetting()
6060
dropDown_writeMemo.SelectedItemIndex = setting.dropDown_writeMemo;
6161
dropDown_deleteMemo.SelectedItemIndex = setting.dropDown_deleteMemo;
6262
}
63-
catch(Exception ex)
63+
catch (Exception ex)
6464
{
6565
print($"<<< ERROR >>>: {ex}");
6666
}
@@ -141,7 +141,7 @@ private void changeEvent_splitButton(RibbonSplitButton btnDst, RibbonButton btnS
141141
btnDst.Tag = btnSrc.Tag;
142142
btnDst.OfficeImageId = btnSrc.OfficeImageId;
143143
}
144-
catch(Exception ex)
144+
catch (Exception ex)
145145
{
146146
print($"<<< ERROR >>>: {ex}");
147147
}
@@ -474,7 +474,7 @@ private void dropDown_shrink_SelectionChanged(object sender, RibbonControlEventA
474474
switchControlState(true);
475475
}
476476

477-
private async void pasteLinkedImages(Excel.Worksheet sheet, Excel. Range cells)
477+
private async void pasteLinkedImages(Excel.Worksheet sheet, Excel.Range cells)
478478
{
479479
int countMax = cells.Count;
480480
await System.Threading.Tasks.Task.Run(() =>
@@ -651,14 +651,14 @@ private void deleteImage(Excel.Worksheet sheet, Excel.Shape shape, Excel.Range s
651651

652652
// Erase the contents of the cell
653653
bool isValueClear = false;
654-
if ( isAll )
654+
if (isAll)
655655
{
656656
isValueClear = true;
657657
}
658658
else
659659
{
660660
// Check the intersection of Shape and Selected cells
661-
if(sheet.Application.Intersect(shapeRange, selectedCells) != null)
661+
if (sheet.Application.Intersect(shapeRange, selectedCells) != null)
662662
{
663663
isValueClear = true;
664664
}
@@ -856,7 +856,7 @@ private void pasteImage(Excel.Worksheet sheet, Excel.Range cell, string imageOrg
856856
writeInfoMemo = dropDown_writeMemo.SelectedItem.Tag.ToString();
857857
comment = (cell.Comment != null) ? cell.Comment.Text() : "";
858858
}
859-
catch(Exception ex)
859+
catch (Exception ex)
860860
{
861861
print($"<<< ERROR >>>: {ex}");
862862
return;
@@ -903,11 +903,11 @@ private string getWriteInfo(string imagePath, string type, string infoInit)
903903
{
904904
;
905905
}
906-
else if ( (type == "name") || (type == "nameLink") )
906+
else if ((type == "name") || (type == "nameLink"))
907907
{
908908
info = System.IO.Path.GetFileName(imagePath);
909909
}
910-
else if ( (type == "path") || (type == "pathLink") )
910+
else if ((type == "path") || (type == "pathLink"))
911911
{
912912
info = imagePath;
913913
}
@@ -1097,8 +1097,8 @@ private bool checkImagePath(string path)
10971097
// Checking the existence and extension
10981098
bool isExist = false;
10991099
string ext = System.IO.Path.GetExtension(path);
1100-
string[] extCheck = {".jpg",".jpeg", ".bmp", ".png", ".gif"};
1101-
if ( extCheck.Contains(ext, System.StringComparer.OrdinalIgnoreCase))
1100+
string[] extCheck = { ".jpg", ".jpeg", ".bmp", ".png", ".gif" };
1101+
if (extCheck.Contains(ext, System.StringComparer.OrdinalIgnoreCase))
11021102
{
11031103
if (System.IO.File.Exists(path))
11041104
{
@@ -1126,7 +1126,7 @@ private string getImagePathFromDialog()
11261126
imagePath = ofd.FileName;
11271127
}
11281128
}
1129-
catch(Exception ex)
1129+
catch (Exception ex)
11301130
{
11311131
print($"ERROR tempBmp: {ex}");
11321132
}
@@ -1137,7 +1137,7 @@ private string getImagePathFromDialog()
11371137

11381138
private Excel.Application getApplication()
11391139
{
1140-
if(Globals.ThisAddIn.Application == null)
1140+
if (Globals.ThisAddIn.Application == null)
11411141
{
11421142
return null;
11431143
}
@@ -1157,7 +1157,7 @@ private Excel.Workbook getActiveWorkBook()
11571157

11581158
private Excel.Worksheet getActiveSheet()
11591159
{
1160-
if(Globals.ThisAddIn.Application.ActiveSheet == null)
1160+
if (Globals.ThisAddIn.Application.ActiveSheet == null)
11611161
{
11621162
return null;
11631163
}
@@ -1167,7 +1167,7 @@ private Excel.Worksheet getActiveSheet()
11671167

11681168
private Excel.Range getSelection()
11691169
{
1170-
if(Globals.ThisAddIn.Application.Selection == null)
1170+
if (Globals.ThisAddIn.Application.Selection == null)
11711171
{
11721172
return null;
11731173
}
@@ -1177,7 +1177,7 @@ private Excel.Range getSelection()
11771177

11781178
private Excel.Range getActiveCell()
11791179
{
1180-
if(Globals.ThisAddIn.Application.ActiveCell == null)
1180+
if (Globals.ThisAddIn.Application.ActiveCell == null)
11811181
{
11821182
return null;
11831183
}
@@ -1237,7 +1237,7 @@ private void editBox_setW_TextChanged(object sender, RibbonControlEventArgs e)
12371237
{
12381238
int w = int.Parse(editBox_setW.Text);
12391239
}
1240-
catch(Exception ex)
1240+
catch (Exception ex)
12411241
{
12421242
print($"<<< Parse error >>>: {ex}");
12431243
editBox_setW.Text = "15";

ImageInserter/WaitDialogForm.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ public WaitDialog()
3232
//
3333
// TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
3434
//
35-
this.ProgressMin = 0; // 処理件数の最小値(0件から開始)
36-
this.ProgressStep = 1; // 何件ごとにメーターを進めるか
35+
this.ProgressMin = 0; // 処理件数の最小値(0件から開始)
36+
this.ProgressStep = 1; // 何件ごとにメーターを進めるか
3737
this.ProgressValue = 0; // 最初の件数
3838

3939
System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
40-
Microsoft.VisualBasic.Interaction.AppActivate(p.Id);
40+
try
41+
{
42+
Microsoft.VisualBasic.Interaction.AppActivate(p.Id);
43+
}
44+
catch (System.Exception) {; }
4145
}
4246

4347
/// <summary>

0 commit comments

Comments
 (0)