【发布时间】:2019-11-20 09:54:34
【问题描述】:
我正在使用 VBA 处理 Access 数据库,它需要从 Excel 工作簿中获取数据。
我需要为打开的书分配一个变量(设置 g_xl = ????)而不打开另一个 Excel 实例(指定打开的工作簿)。
Sub AssignVariableToExcelApplication()
Dim g_xl As Excel.Application
Dim strComputer As String
Dim objWMIService As Object
Dim colitems As Object
Dim objitem As Object
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colitems = objWMIService.ExecQuery("SELECT * FROM Win32_Process", , 48)
Dim row As Integer
row = 1
For Each objitem In colitems
If objitem.Name = "EXCEL.EXE" Then
Debug.Print objitem.ProcessID & vbCrLf & _
objitem.Name & vbCrLf & _
objitem.Caption & vbCrLf & _
objitem.CommandLine & vbCrLf & _
objitem.ExecutablePath
'This is the question
'Set g_xl = objitem ?????? (I need that g_xl appoints to objitem)
Exit For
End If
Next
End Sub
【问题讨论】: