VB高手,想利用VB在同一目录下替换固定字符,已经在word页面里面做了一个: Text = "双壁单影" Replacemen
VB高手,想利用VB在同一目录下替换固定字符,已经在word页面里面按照网络达人写法了一个程序,但是里面只能是Text="需变更内容".Replacement.Text=...
VB高手,想利用VB在同一目录下替换固定字符,已经在word页面里面按照网络达人写法了一个程序,但是里面只能是Text = "需变更内容"
.Replacement.Text = "变更后内容",请问如何通过程序实现:在word页面里面输入"需变更内容" "变更后内容",
然后执行程序,就可以变更,达到同时替换多个固定字符的功能
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim myPas As String, myPath As String, i As Integer, myDoc As Document
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "选择目标文件夹"
If .Show = -1 Then
myPath = .SelectedItems(1)
Else
Exit Sub
End If
End With
myPas = InputBox("请输入打开密码:")
With Application.FileSearch
.LookIn = myPath
.FileType = msoFileTypeWordDocuments
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Set myDoc = Documents.Open(FileName:=.FoundFiles(i), Passworddocument:=myPas)
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "IT部落窝"
.Replacement.Text = " ittribalwo "
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
myDoc.Save
myDoc.Close
Set myDoc = Nothing
Next
End If
End With
Application.ScreenUpdating = True
End Sub
To vogri81:
能不能把您的这段程序帮我整合到 我的那个程序里面 ,再帮我吧STRA STRb的设置方法告诉我下 谢谢 展开
.Replacement.Text = "变更后内容",请问如何通过程序实现:在word页面里面输入"需变更内容" "变更后内容",
然后执行程序,就可以变更,达到同时替换多个固定字符的功能
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim myPas As String, myPath As String, i As Integer, myDoc As Document
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "选择目标文件夹"
If .Show = -1 Then
myPath = .SelectedItems(1)
Else
Exit Sub
End If
End With
myPas = InputBox("请输入打开密码:")
With Application.FileSearch
.LookIn = myPath
.FileType = msoFileTypeWordDocuments
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Set myDoc = Documents.Open(FileName:=.FoundFiles(i), Passworddocument:=myPas)
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "IT部落窝"
.Replacement.Text = " ittribalwo "
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
myDoc.Save
myDoc.Close
Set myDoc = Nothing
Next
End If
End With
Application.ScreenUpdating = True
End Sub
To vogri81:
能不能把您的这段程序帮我整合到 我的那个程序里面 ,再帮我吧STRA STRb的设置方法告诉我下 谢谢 展开
1个回答
展开全部
以下代码经测试可行
Private Sub Command1_Click()
Dim strA, strB, strC, strRe, strRes
'-----从text2中找出和text1重复的部分-----
strA = Text1.Text
strB = Text2.Text
For i = 1 To Len(strA)
strB = Replace(strB, Mid(strA, i, 1), "")
Next
strC = strB
'-----从text1中找出和text2重复的部分-----
strA = Text2.Text
strB = Text1.Text
For i = 1 To Len(strB)
strB = Replace(strB, Mid(strA, i, 1), "")
Next
strC = strC & strB
'-----过滤结果中重复的部分-----
For i = 1 To Len(strC)
strRe = Mid(strC, i, 1)
strRes = Replace(strC, strRe, "", , 1)
If InStr(1, strRes, strRe, vbTextCompare) <> 0 Then
strC = Replace(strRes, strRe, "") & strRe
End If
Next
Text3.Text = strC
End Sub
Private Sub Command1_Click()
Dim strA, strB, strC, strRe, strRes
'-----从text2中找出和text1重复的部分-----
strA = Text1.Text
strB = Text2.Text
For i = 1 To Len(strA)
strB = Replace(strB, Mid(strA, i, 1), "")
Next
strC = strB
'-----从text1中找出和text2重复的部分-----
strA = Text2.Text
strB = Text1.Text
For i = 1 To Len(strB)
strB = Replace(strB, Mid(strA, i, 1), "")
Next
strC = strC & strB
'-----过滤结果中重复的部分-----
For i = 1 To Len(strC)
strRe = Mid(strC, i, 1)
strRes = Replace(strC, strRe, "", , 1)
If InStr(1, strRes, strRe, vbTextCompare) <> 0 Then
strC = Replace(strRes, strRe, "") & strRe
End If
Next
Text3.Text = strC
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询