学习Excel技术,关注微信公众号:excelperfect
标签:VBA打开VBE,在名为“模块1”的标准模块中输入下面的代码:Sub replaceConstant() Dim project As VBIDE.VBProject Dim codeMod As VBIDE.CodeModule Dim component As VBIDE.VBComponent Dim n As Long, s As String Dim Old_text As String Dim New_text As String Old_text = "iLong" New_text = "iiLong" For Each project In Application.VBE.VBProjects For Each component In project.VBComponents If component.Name "模块1" Then Set codeMod = component.CodeModule With codeMod For n = 1 To .CountOfLines s = .Lines(n, 1) If Len(Trim$(s)) Then If s Like "*" & Old_text & "*" Then s = Replace$(s, Old_text, New_text) .DeleteLines n, 1
………………………………