1 2 3 4 5 6 7 8 9 |
Sub Sample1() If Workbooks("Book1.xlsx").MultiUserEditing = True Then MsgBox "共有ファイルです。" Else MsgBox "共有ファイルではありません。" End If End Sub |
共有ファイルに実行できない処理を実行した場合、エラーとなってしまいます。
![%e5%af%be%e8%b1%a1%e3%81%ae%e3%83%96%e3%83%83%e3%82%af%e3%81%8c%e5%85%b1%e6%9c%89%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%81%8b%e3%83%81%e3%82%a7%e3%83%83%e3%82%af%e3%81%99%e3%82%8b_1](http://excelmemo.com/wp-content/uploads/2016/11/対象のブックが共有ファイルかチェックする_1-300x141.jpg)
次のようにチェック処理を入れておけば回避することができます。
1 2 3 4 5 6 7 8 9 10 |
Sub Sample2() If Workbooks("Book1.xlsx").MultiUserEditing = False Then ' 共有ファイルではない場合、セル結合 With Workbooks("Book1.xlsx").Sheets("Sheet1") Range(.Cells(1, 1), .Cells(2, 2)).MergeCells = True End With End If End Sub |