|
Sub tihuan()
On Error Resume Next
Dim i As Integer
Dim it As String
Set wdapp = CreateObject("word.application")
Dim myrange
Application.DisplayAlerts = False
Application.CutCopyMode = False
Application.ScreenUpdating = False
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "请选择模版文件"
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Word Files", "*.doc;*.docx"
If .Show = 0 Then
Exit Sub
End If
it = .SelectedItems(1)
End With
Set wd = wdapp.documents.Open(it)
wd.ActiveWindow.Selection.Copy
range("a1").Select
ActiveSheet.Paste
Debug.Print ActiveSheet.range("a1")
With wd.ActiveWindow.Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "设计单位"
.Replacement.Text = "aaaaaaaa"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
wd.SaveAs Filename:=ThisWorkbook.Path & "\" & ActiveSheet.Cells(1, 1)
wd.Close True
wapp.Quit
Set wd = Nothing
Set wapp = Nothing
Application.DisplayAlerts = True
Application.CutCopyMode = True
Application.ScreenUpdating = True
End Sub
|
|