VB高手,想利用VB在同一目录下替换固定字符,已经在word页面里面做了一个: Text = "双壁单影" Replacemen

[复制链接]
查看11 | 回复1 | 2010-12-24 11:35:38 | 显示全部楼层 |阅读模式
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的设置方法告诉我下 谢谢

回复

使用道具 举报

千问 | 2010-12-24 11:35:38 | 显示全部楼层
以下代码经测试可行Private Sub Command1_Click()Dim strA, strB, strC, strRe, strRes'-----从text2中找出和text1重复的部分-----strA = Text1.TextstrB = Text2.TextFor i = 1 To Len(strA)strB = Replace(strB, Mid(strA, i, 1), "")NextstrC = strB'-----从text1中找出和text2重复的部分-----strA = Text2.TextstrB = Text1.TextFor i = 1 To Len(strB)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行