尝试此代码
- Option Explicit
- '===============================================================
- 'require reference to Microsoft VBScript Regular Expressions 5.5
- '===============================================================
- Sub ahha()
- Dim s As String
- Dim i As Long
- Dim cnt As Integer
- Dim newstr As String
- Dim num As Double
- Dim regex As RegExp
- Set regex = New RegExp
- regex.IgnoreCase = False
- regex.Global = False
- newstr = "Boo"
- regex.Pattern = "(acm-)(.*?)(-sht)(\d+)"
- ' Where:
- ' (acm-)- constant part
- ' (.*?) - any charachters you need to replace with 'newstr'
- ' (-sht)- constant part
- ' (\d+) - any digits
- Dim olayout As AcadLayout
- For Each olayout In ThisDrawing.Layouts
- If Not olayout.ModelType Then
- ThisDrawing.ActiveLayout = olayout
- olayout.Name = regex.Replace(olayout.Name, "$1" & newstr & "$3" & "$4")
- Debug.Print olayout.Name 'debug only
- End If
- Next
- Set regex = Nothing
- ThisDrawing.SetVariable "tilemode", 1
- End Sub
|