1、首先在开发工具中打开VBA编辑器
2、在单元格区域当中输入一些内容作为例子
3、在VBA编辑器中插入模块
4、在模块当中输入如下代码,然后运行Sub 为公式添加标注() On Error Go哌囿亡噱To endd Set Rng=Selection.Cells.SpecialCells烫喇霰嘴(xlCellTypeFormulas) For Each cell In Rng cell.ClearComments With cell.AddComment .Text Text:=cell.Formula With .Shape .TextFrame.AutoSize=True .Fill.ForeColor.SchemeColor=44 .AutoShapeType=msoShapePlaque If Len(cell.Formula) > 50 And Len(cell.Formula) < 100 Then .Width=300 .Height=32 ElseIf Len(cell.Formula)>=100 And Len(cell.Formula)<150 Then .Width=300 .Height=48 ElseIf Len(cell.Formula)>=150 And Len(cell.Formula)<300 Then .Width=300 .Height=95 ElseIf Len(cell.Formula)>=300 And Len(cell.Formula)<1024 Then .Width=300 .Height=150 End If .Visible=False End With End With Next cellendd:End Sub
5、选中单元格区域A1∶觊皱筠桡C8,然后利用快捷键Alt+F8调出运行宏窗口,并单击“执行”按钮,所有公式的单元格都已建立批注,其余单元格忽略