マクロの動作にも今までのバージョンと違いあるみたい。
CheckBox1.Value = 1 でチェックつけられるのに
If Me.CheckBox1.Value = 1 Then ではだめで
If Me.CheckBox1.Value = 1 Or CheckBox1.Value = True Then にしないといけないみたい。
○.×時間 表記から ○時間×分 表記に変換するマクロを頼まれ作った時に偶然判明しました。
以下は実際のコード。
ヘタレだけど覚え書きなので。
最終更新日時:2007-07-13 02:04:40 JST
ThisWorkbook
Private Sub Workbook_Open()
Load time_upp
time_upp.CheckBox1.Value = 1
time_upp.Show
End Sub
Public Sub 変換ウインドウ表示()
Load time_upp
time_upp.CheckBox1.Value = 1
time_upp.Show
End Sub
‘CheckBox1.Value = 1 とすることでチェックが入った状態にしています
Form time_upp
‘Author : maya 2007.07.12
Private Sub CommandButton1_Click() ‘変換 ボタン
On Error GoTo errorH
Dim i, iCount As Integer ‘回数
Dim iValue As Single ‘時間。小数点扱うため浮動小数点数型で宣言
‘選択されたセルの数を変数に代入
iCount = Application.Selection.count
‘選択されたセルがない場合はエラー文を出し終了
If iCount = 0 Then
MsgBox "選択された数を判別できませんでした。"
Exit Sub
End If
‘選択されたセルの数だけ変換処理を繰り返す
For i = 1 To iCount
‘空欄のセルが選択されている場合はエラー文を出し次へ
If ActiveCell.Value = "" Then
MsgBox "選択範囲に空欄が含まれています。"
Else
‘空欄でない場合のみ変換処理
iValue = ActiveCell.Value
ActiveCell.Value = iValue / 24
‘CheckBox1にチェックがついていれば書式も変更する。
If Me.CheckBox1.Value = 1 Or _
Me.CheckBox1.Value = True Then
ActiveCell.NumberFormatLocal = "[h]:mm"
End If
‘Selection.Next.Activate ‘右に動いてしまい使えない
‘アクティブなセルをひとつ下に移動させる
‘選択範囲に対し実行ではないので本来これではない方がいい
ActiveCell.Offset(1, 0).Activate
End If
Next i
Exit Sub
errorH: ‘エラー処理
MsgBox "エラーが発生しました。mayaまで連絡してください。" & vbCrLf & _
Err.Number & Err.Description, vbCritical, 予期せぬエラー
Exit Sub
End Sub
Private Sub CommandButton2_Click() ‘閉じる ボタン
Unload Me
End Sub