怎样在VB中控制Word(一)

来源:互联网 发布:c语言在文件末尾追加 编辑:程序博客网 时间:2024/05/04 21:42

网上看了很多,总结了一下,一些已经成功,一些还需要继续验证。

    '方法1 OK
    'Dim StartDoc As Long
    'Dim Scr_hDC As Long
    'Scr_hDC = GetDesktopWindow()
    'StartDoc = ShellExecute(Scr_hDC, "Open", strApp, "", "C:/", SW_SHOWNORMAL)

    '方法2
    'Shell ("C:/Program Files/Microsoft Office/Office/winword.exe " & strApp)

    '方法3 OK
    '问题是没有捕捉到打开文件的关闭,如果在后台打开并有写操作,如果没有关闭进程,将会对多个副本进行操作
    'Dim WordApp As Word.Application
    'Set WordApp = New Word.Application
    'Set WordApp = CreateObject("Word.Application")
    'WordApp.Visible = True
    'WordApp.Documents.Open strApp

    '方法四
    'OLE1.CreateEmbed vbNullString, "Word.Document"
    'Set oDocument = OLE1.object
    'oDocument.SaveAs strApp

    '方法五
    '
    'winexec( 'explorer.exe ' ' http://www.tdown.com',1)

    '方法6
    '使用WordBasic
    Set oWord = CreateObject("Word.Basic")
    oWord.Open strApp

OLE方法:
 具体见:http://support.microsoft.com/kb/q242243/  

 使用函数API函数   Shellexecute       
 具体见:http://support.microsoft.com/default.aspx?scid=kb;en-us;Q170918

另一篇文章:http://www.yesky.com/20010919/197627.shtml

原创粉丝点击