2010年6月4日 星期五

VB.net 呼叫 WORD code

'開啟 WORD 文件 '*************************************************************************************************** '別忘記新增 參考 WORD 11
Dim objWord As Object = CreateObject("Word.Application") '使用完後 就釋放資源 故使用Using
Dim objDoc
Dim objSelection
objWord.Visible = False
objDoc = objWord.Documents.Open(My.Application.Info.DirectoryPath & "\UserData.doc")
'objDoc = objWord.Documents.Add()
objSelection = objWord.Selection

'選擇題輸出
If chkopS.Checked = True Then
objSelection.TypeText("※ 科目:" & selSubject)
objSelection.TypeParagraph()

'objSelection.TypeText(DashLine)
'objSelection.TypeParagraph()
objSelection.TypeText(Sv(0))
objSelection.TypeParagraph()
End If

'取代特殊字串!
Const wdReplaceAll = 2
'取代1
objSelection.WholeStory()
objSelection.Find.ClearFormatting()
objSelection.Find.Replacement.ClearFormatting()
With objSelection.Find
.Text = "<---><---><--->"
.Replacement.Text = "^l"
.Forward = True
'.Wrap = objSelection.wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
objSelection.Find.Execute(Replace:=wdReplaceAll)



'objDoc = objWord.Documents.Open("c:\scripts\test.rtf")
objDoc.SaveAs(My.Application.Info.DirectoryPath & "\" & FN)
objDoc = Nothing
objWord.Quit()
objWord = Nothing
GC.Collect()

沒有留言:

張貼留言

追蹤者