在 Excel 工作表上,我希望文本出现在背景中,或者当您单击它时文本会消失,以便为使用它的人显示说明。
我找到了代码,但你无法添加不会消失的文本。
有没有一种方法可以让文本在背景中消失,当您输入新文本时,即使您点击它,文本仍然存在,也许像水印一样,但会消失?
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
listecellules = "/" & Range("C9").Address & "/" & Range("C10").Address & "/" & Range("C18").Address & "/" & Range("C26").Address & "/" & Range("C32").Address & "/"
If listecellules Like "*/" & Target.Address & "/*" Then
If Target <> "" Then
texte = Target.Value
Target = ""
temps_début = Timer
Do While Timer < temps_début + 1
DoEvents
Loop
If Target = "" Then
Target.Value = texte
End If
End If
End If
End Sub
我找到了可以接受的代码:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then
Dim Colr As Long, Txt As String
If Target.Address(0, 0) = "D3" Then
Txt = "Enter Last Name Here"
ElseIf Target.Address(0, 0) = "D4" Then
Txt = "Enter First Name Here"
End If
Application.EnableEvents = False
If Len(Target.Value) = 0 Or Target.Value = Txt Then
Target.Font.ColorIndex = 16
Target.Value = Txt
Else
Target.Font.ColorIndex = 1
End If
Application.EnableEvents = True
End If
End Sub