VBA:在文本框中查找string并将其更改为某个string

我想创build一个macros,每个月在文本框中改变为在对话框中input的某个月份。
这是我写的。 没有错误,但也没有做任何工作。 你能帮忙find问题吗? 谢谢。

Sub ChangeMonth() Dim xWs As Worksheet Dim shp As Shape Dim xFindStr As String Dim xReplace As String Dim z As Integer Set xWs = Application.Sheets("Mail") xReplace = Application.InputBox("Replace to :", "Replacement", "", Type:=2) 'On Error Resume Next For Each shp In xWs.Shapes xValue = shp.TextFrame.Characters.Text For x = 1 To 12 shp.TextFrame.Characters.Text = VBA.Replace(xValue, MonthName(x), "xxxx") Next x shp.TextFrame.Characters.Text = VBA.Replace(xValue, "xxxx", xReplace) Next End Sub 

这个主要问题是你用“xxxx”replace了所有的MonthName,但是你直接把这个值放在了形状的文本中,但是你使用了xValue

 Sub ChangeMonth() Dim xwS As Worksheet Dim ShP As Shape Dim xFindStr As String Dim xReplace As String Dim z As Integer Set xwS = ThisWorkbook.Sheets("Mail") xReplace = InputBox("Replace to :", "Replacement", "", Type:=2) 'On Error Resume Next For Each ShP In xwS.Shapes xValue = ShP.TextFrame.Characters.Text For x = 1 To 12 xValue = VBA.Replace(xValue, MonthName(x), xReplace) Next x ShP.TextFrame.Characters.Text = xValue Next ShP End Sub