Excel自定义提示框/批注/注释水貔藻疽,悬浮单元格上,类似数据有效性输入时提示的那样,但可以自定义。本例实现从异常解彩惚湛厦释放在单元格Q3至V27,当点击I3至N27任意单元格时,检查如有对应解释则探出文本框显示,如没有则不显示,或点击I3至N27之外单元格删除提示框。需要的,可以修改为适合自己的。可以帮助解决报告界面因备注长而不美观,保持整洁。有用,记得投票哦。自己不会修改或遇到问题的,可以QQ16990613
工具/原料
MSExcel2010及以上
VBA
方法/步骤
1、引用MsForms2.0objectlibrary.
2、复制以下代码至需要使用的工作表代码页里,代码备注见图片OptionExplicitPriv瞢铍库祢ate胨检馁秣SubWorksheet_SelectionChange(ByValTargetAsRange)OnErrorResumeNextApplication.EnableEvents=FalseApplication.ScreenUpdating=FalseDimoleAsOLEObjectDimolexAsOLEObjectDimobj,objzDimnmAsVariantDimlbxAsBooleanDimoWSAsWorksheetSetoWS=Target.ParentIfoWS.OLEObjects.Count>=1ThenForEacholeInMe.OLEObjectsIfole.Name="sysLblz"ThenSetobj=ole.Objectnm=obj.CaptionoWS.OLEObjects(nm).Deletelbx=TrueEndIfNextEndIfIflbx=FalseThen'ifnotexistsysLblz,generateitforsavetextboxnameSetole=oWS.OLEObjects.Add(ClassType:="Forms.label.1",Link:=False,DisplayAsIcon:=False,Left:=1,Top:=1,Width:=1,Height:=1)ole.Name="sysLblz"Setobj=ole.Objectobj.Caption="sysLblz"EndIfIf(Target.Column>=9AndTarget.Column<=15)And(Target.Row>=3_AndTarget.Row<=27)AndTarget.Cells.Count=1ThenIfLen(Cells(Target.Row,Target.Column+8).Value)>0ThenSetolex=oWS.OLEObjects.Add(ClassType:="Forms.TextBox.1",Link:=False,DisplayAsIcon:=False)',Width:=500,Height:=200olex.Visible=Falseolex.Name="systxtL"'DoEventsobj.Caption=olex.NameSetobjz=olex.ObjectWithobjz.FontSize=16.MultiLine=True.WordWrap=True.Text=Cells(Target.Row,Target.Column+8).Value'ActiveCell.Value.ForeColor=vbRed.BackColor=RGB(255,255,0).ScrollBars=2.SpecialEffect=0EndWithWitholex'.Visible=False.Shadow=False.Width=500.Height=200.Top=Target.Top+Target.Height.Left=Target.LeftEndWithEndIfEndIf'DoEventsolex.Visible=TrueApplication.ScreenUpdating=TrueApplication.EnableEvents=TrueEndSub