'=============打开word==============
Function OpenWord(FileName)
Dim wordApp As New Word.Application
Dim wordDoc As New Word.Document
Set wordApp = CreateObject("Word.Application")
wordApp.Visible = False
Set wordDoc = wordApp.Documents.Open(FileName)
End Function
'============替换关键字===========
Function ReplaceWord(SearchStr, ReplaceStr)
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = SearchStr
.Replacement.Text = ReplaceStr
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Function
'============另存为===================
Function SaveAsWord(DiskStr, NameStr)
ChangeFileOpenDirectory DiskStr
ActiveDocument.SaveAs FileName:=NameStr, FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= False
Application.Documents.Close
Application.Quit
End Function
'===================清除对象============
Function CloseWord()
Set wordDoc = Nothing '清除文件实例
Set wordApp = Nothing '清除WORD实例
End Function
'===================用VB调用WORD代码============
Private Sub Form_Load()
Dim wp As New Word.Application
Dim wd As New Word.Document
wp.Visible = True
Set wd = wp.Documents.Open("c:\22075847937.doc")
Dim neirong As String
neirong = wd.Content.Text
MsgBox "该Word文件的内容为:" & vbNewLine & neirong
End Sub