本文介绍了通过VBA的Word文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为复杂的Excel VBA模块的一部分,我想打开一个Word文件(包含一个AutoOpen宏)...我可以使用"Application.ActivateMicrosoftApp xlMicrosoftWord"打开
Word,但我可以弄清楚如何打开一个特定的文件...

推荐答案

Sub OpenWordDoc()
'In order to use this code you must set a reference to the
'Word object library by doing this. In the VB Editor click
'Tools, References. Then search for Microsoft Word n.n Object Library
'where n.n will depend on your version of Word.

Dim wdApp As Word.Application, wdDoc As Word.Document

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0

Set wdDoc = wdApp.Documents.Open("C:\temp\anyolddoc.doc")

wdApp.Visible = True

'You can now do whatever you like with the Word document e.g.

wdDoc.PrintOut
wdDoc.SaveAs "C:\temp\hello.doc"
wdDoc.Activate
'etc

End Sub


来源:MrExcel.com

Source: MrExcel.com


这篇关于通过VBA的Word文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 14:47