2011年1月14日 星期五

VB.NET Windows Application 如何開啟 Word 樣板(*.dot)

How VB.NET Windows Application to open an Word Template(*.dot)

Shell("C:\123.dot") '失敗,變成文件1 Fail ,Docutment1
System.Diagnostics.Process.Start("C:\123.dot") '失敗,變成文件1 Fail ,Docutment1

'成功開啟123.dot
'Success open as 123.dot
'Way1
Dim myProcess As New Process

Try

myProcess.StartInfo.FileName = "C:\123.dot"
myProcess.StartInfo.Verb = "Open"
myProcess.StartInfo.CreateNoWindow = True
myProcess.Start()

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try


'Way 2
Dim wdApp As Object ' Declare variable to hold the reference.

Try

wdApp = CreateObject("WORD.Application")
wdApp.Visible = True
wdApp.Application.WindowState = wdWindowStateMaximize
wdApp.DOCUMENTS.Open("C:\123.dot")
wdApp = Nothing

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try


沒有留言: