Excel VBAオブジェクト(図形)の保護
Excel VBAのオブジェクト(図形)の保護について質問させて頂きます。
現在、社内の打合せコーナーの予約表をExcel VBAで作成しておりまして、予約したい開始時間に名前、終了時間に*を入れると、図形の矢印が描画される様になっています。(画像をご参照)
しかし、この矢印が動かせてしまう為、開始時間の名前と終了時間の*が入っている間は動かせない様にし、名前と*を消すと矢印が消える様にしたいのですが、どの様にコーディングすれば実現できるでしょうか?
ご存知の方、ご教示宜しくお願い致します。
↓は予約表の現在のVBAのコードです。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim stflg As String
Dim sth As Long
Dim stw As Long
Dim edh As Long
Dim edw As Long
Const maxw = 26
Const maxh = 66
Const cellh = 13.5
Const cellw = 33.85
'入力チェック
With ActiveSheet
For i = 6 To maxh Step 2
stflg = ""
For j = 3 To maxw
If .Cells(i, j).Value <> "" Then
If .Cells(i, j).Value = "*" Then
If stflg = "" Then
MsgBox "入力内容が誤りです"
.Cells(i, j).Select
Exit Sub
Else
stflg = ""
End If
Else
stflg = "1"
End If
End If
Next j
Next i
End With
'矢印を全て削除する
For Each oShape In ActiveSheet.Shapes
If oShape.Type = msoLine Then oShape.Delete
Next
With ActiveSheet
For i = 6 To maxh Step 2
stflg = ""
For j = 3 To maxw
If .Cells(i, j).Value <> "" Then
If .Cells(i, j).Value = "*" Then
edh = ((i - 2) * cellh) + (cellh / 1.6)
edw = 60 + ((j - 2) * cellw)
With .Shapes.AddLine(stw, sth, edw, edh).Line
.ForeColor.SchemeColor = 0
.EndArrowheadStyle = msoArrowheadStealth
.Weight = 1.5
End With
stflg = ""
Else
If stflg = "" Then
sth = ((i - 2) * cellh) + (cellh / 1.6)
stw = 60 + ((j - 3) * cellw)
stflg = "1"
Else
edh = ((i - 2) * cellh) + (cellh / 1.6)
edw = stw + cellw
With .Shapes.AddLine(stw, sth, edw, edh).Line
.ForeColor.SchemeColor = 0
.EndArrowheadStyle = msoArrowheadStealth
.Weight = 1.5
sth = ((i - 2) * cellh) + (cellh / 1.6)
stw = 60 + ((j - 3) * cellw)
End With
End If
End If
End If
If j = maxw And stflg <> "" Then
edh = ((i - 2) * cellh) + (cellh / 1.6)
edw = stw + cellw
With .Shapes.AddLine(stw, sth, edw, edh).Line
.ForeColor.SchemeColor = 0
.EndArrowheadStyle = msoArrowheadStealth
.Weight = 1.5
End With
End If
Next j
Next i
End With
End Sub
お礼
有難うございます。 今、自宅の2003で、あたらしいBOOKでやったらOKでした。 多分、他の原因だったのでしょうね。 うまく行きました。 いつもいつもお世話になります。