VBA 如何引用一个已打开的word,我在一个过程里打开了word文档,编辑后想在另一个过程里调用word里的内容 15
PrivateSubCommandButton9_Click()Setmyapp=CreateObject("word.Application")myapp.Visibl...
Private Sub CommandButton9_Click()
Set myapp = CreateObject("word.Application")
myapp.Visible = -1
Set myworkbook = myapp.Documents.Open("C:\网络公共盘\Normal\C.docm")
UserForm5.Show 0
End Sub
Private Sub CommandButton1_Click()
Dim j As Integer
Dim y As String
Dim x As String
Dim a As String
Dim myworkbook As Word.Document
Set myworkbook = Application.Documents("C:\网络公共盘\Normal\C.docm")
上面这句执行不了啊
x = myworkbook.Tables(1).Cell(1, 4).Range.Text 展开
Set myapp = CreateObject("word.Application")
myapp.Visible = -1
Set myworkbook = myapp.Documents.Open("C:\网络公共盘\Normal\C.docm")
UserForm5.Show 0
End Sub
Private Sub CommandButton1_Click()
Dim j As Integer
Dim y As String
Dim x As String
Dim a As String
Dim myworkbook As Word.Document
Set myworkbook = Application.Documents("C:\网络公共盘\Normal\C.docm")
上面这句执行不了啊
x = myworkbook.Tables(1).Cell(1, 4).Range.Text 展开
1个回答
展开全部
建议把myworkbook 改为全局变量,在打开过程赋值后,后面的
Dim myworkbook As Word.Document
Set myworkbook = Application.Documents("C:\网络公共盘\Normal\C.docm")
'上面这句执行不了啊
这两句去掉,不再重新定义并赋值。直接使用即可。
这里主要是你在程序内部打开的,操作起来还算便利。如果是在程序运行之前就已经打开的Word可以用其他方式(GetObject)获得。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询