2016-11-27 1 views
0

私はVBAにはとても親しまれています。私はWordで私のユーザーフォームのいくつかのキューバナーを作成しようとしています。私が立ち往生する前に、私は約半分の方法を得た。私はキューバナーが消える場所を持っていて、フォーカスがあるとテキストボックスをクリアします。ユーザーが独自のテキストを入力すると、そのテキストも保持されます。気取ったキューバナー

しかし、ユーザーがクリアしたテキストボックスに何も入力しなければ、その属性(グレーのテキストとイタリック体)とともにキューのバナーを置き換えます。私はそれを働かせるように見えません。以下に、このテキストボックスに関連するすべてのコードを示します。問題は私が思うLeaveイベントです。

Private Sub UserForm_Initialize() 

     Me.txbShipToName1.Text = "name" 
     Me.txbShipToName1.Font.Italic = True 
     Me.txbShipToName1.ForeColor = &H80000006 

End Sub 

Private Sub txbShipToName1_Enter() 

     If Me.ActiveControl Is Me.txbShipToName1 And Me.txbShipToName1.Text = "name" Then 
      txbShipToName1.Font.Italic = False 
      txbShipToName1.ForeColor = &H80000008 
      txbShipToName1.Text = "" 
     End If 

End Sub 

Private Sub txbShipToName1_Leave() 

     If Me.ActiveControl Is Not txbShipToName1 And Me.txbShipToName1.Text = "" Then 
      txbShipToName1.Font.Italic = True 
      txbShipToName1.ForeColor = &H80000006 
      txbShipToName1.Text = LCase(txbShipToName1.Text) 
      txbShipToName1.Text = "name" 
     End If 

End Sub 

Private Sub txbShipToName1_Change() 

     If Me.ActiveControl Is Me.txbShipToName1 And Me.txbShipToName1 <> "name" Then 
      txbShipToName1.Text = UCase(txbShipToName1.Text) 
     End If 

End Sub 

答えて

0

私は解決策を知りたいと思う他の人のためにここに入れています。数日後に、私は別のコードをつぶしていたときに、私は物事を複雑にしていたことに気づきました。私はActiveControlテストを省略しました。これは、基本的にEnterイベントとExitイベントに組み込まれているためです。ここには更新されたコードがあります。

Private Sub UserForm_Initialize() 
'Populates cue banners 
    Me.txbShipToName1.Text = "Name" 
    Me.txbShipToName1.Font.Italic = True 
    Me.txbShipToName1.ForeColor = &H80000011 
End Sub 

Private Sub txbShipToName1_Enter() 
'Removes cue banner upon entering textbox 
    If Me.txbShipToName1.Text = "Name" Then 
     txbShipToName1.Font.Italic = False 
     txbShipToName1.ForeColor = &H80000012 
     txbShipToName1.Text = "" 
    End If 

End Sub 'txbShipToName1_Enter() 
Private Sub txbShipToName1_Change() 

'Converts textbox to uppercase 
    If Me.txbShipToName1.Text <> "Name" Then 
     txbShipToName1.Text = UCase(txbShipToName1.Text) 
    End If 
End Sub 'txbShipToName1_Change() 

Private Sub txbShipToName1_Exit(ByVal Cancel As MSForms.ReturnBoolean) 
'Replaces cue banner upon exiting textbox 
    If Me.txbShipToName1.Text = "" Then 
     txbShipToName1.Font.Italic = True 
     txbShipToName1.ForeColor = &H80000011 
     txbShipToName1.Text = "Name" 
    End If 
End Sub 'txbShipToName1_Exit(ByVal Cancel As MSForms.ReturnBoolean) 
関連する問題