我正在尝试从 word 中操作 excel 工作簿。一切都运行良好,直到突然我无法从 ActiveCell.Value 得到响应
问题一直发生在这段代码的底部,我尝试在 msgbox 中显示值,但没有出现 msgbox。
之前的命令如:
worksheetJobs.Activate
和
.Cells(1500, fichierColumn).Select
工作正常。
奇怪的是,我正在研究这个(在我发布的内容之后有一整块代码),然后突然之间我什至无法得到这个非常基本的东西来回应......
Dim excelObj As Excel.Application
Dim oWB As Excel.Workbook
'If Excel is running, get a handle on it; otherwise start a new instance of Excel
On Error Resume Next
Set excelObj = GetObject(, "Excel.Application")
If Err Then
MsgBox "excel is not running"
Set excelObj = New Excel.Application
excelObj.Visible = True
On Error GoTo Err_Handler
Set oWB = excelObj.Workbooks.Open(Filename:=todoWorkbook)
Else
MsgBox "excel is running"
Dim wb As Workbook
For Each wb In excelObj.Workbooks
If wb.Name = toDoName Then
Set oWB = wb
Exit For
End If
Next wb
End If
MsgBox oWB.Name
Dim fichierColumn As Integer
Dim outMots As Integer
Dim outLignes As Integer
Dim langOut As Integer
fichierColumn = 5
outMots = 17
outLignes = 18
langOut = 9
Dim worksheetJobs As Excel.Worksheet
Set worksheetJobs = oWB.Worksheets("Liste jobs")
worksheetJobs.Activate
With worksheetJobs
.Cells(1500, fichierColumn).Select
Dim tempStr As String
tempStr = ActiveCell.Value
MsgBox tempStr
End With
'Set excelObj = Nothing
'Set oWB = Nothing
Exit Sub
Err_Handler:
MsgBox todoWorkbook & " caused a problem. " & Err.Description, vbCritical, _
"Error: " & Err.Number
End Sub