Excel进程不closures,代码每隔一秒执行一次

我有一些命令button,通过发送访问表到Excel电子表格,并进行一些格式化,并在其中input一些公式。 其他的命令button可以工作,但是这个在LastRowInventory行。

我相信它与oBook但我不知道如何解决这个问题。 我认为它是因为它试图得到它已经得到的一个对象。 它每两秒钟顺利运行,但不closuresexcel进程。 我在过去几个小时内解决这个问题的尝试没有奏效。

我得到的错误如下:

 Run-time error '462': The remote server machine does not exist or is unavailable 

任何帮助表示赞赏。 我相信这是一个简单的解决办法,但不能完全明白,我对编程相当陌生。 代码如下。

 Private Sub INVENTORYLIST_Click() DTable = InputBox("Input Table Name") '****************************TRANSFER TO EXCEL******************************** Dim strWorksheetPathTable As String strWorksheetPathTable = "O:\GData\Downstream_LNG\Data Mgmt\CEDA\Reports\" & DTable & "\" & DTable & ".xls" DoCmd.TransferSpreadsheet transfertype:=acExport, _ spreadsheettype:=acSpreadsheetTypeExcel12, _ TableName:=("" & DTable & "_INVENTORY LIST"), FileName:=strWorksheetPathTable, _ hasfieldnames:=True, _ Range:="InventoryList" '****************************FORMAT INVENTORY SHEET*********************************** Dim xlApp As Object Dim xlWB As Object Set xlApp = CreateObject("Excel.Application") Dim oBook As Excel.Workbook Dim InventoryListSheet As Excel.Worksheet Dim SummarySheet As Excel.Worksheet Set xlWB = xlApp.Workbooks.Open("" & strWorksheetPathTable & "") Set oBook = GetObject("" & strWorksheetPathTable & "") Set InventoryListSheet = oBook.Sheets("InventoryList") Set SummarySheet = oBook.Sheets("Summary") With xlWB With InventoryListSheet 'Some Spreadesheet Formatting in here End With End With '****************************CREATE OE STATUS BREAKDOWN CALCULATIONS ON SUMMARY SHEET********************** Dim LastRowInventory As Long LastRowInventory = oBook.Sheets("InventoryList").Range("A" & Rows.Count & "").End(xlUp).Row With xlWB With SummarySheet 'Some Spreadsheet Formulas here End With End With '*********************************ORDER WORKSHEETS************************************* With xlWB .Sheets("InventoryList").Select .Sheets("InventoryList").Move Before:=oBook.Sheets(1) .Sheets("Summary").Select .Sheets("Summary").Move Before:=oBook.Sheets(1) End With If Not SummarySheet Is Nothing Then Set SummarySheet = Nothing End If If Not InventoryListSheet Is Nothing Then Set InventoryListSheet = Nothing End If If Not oBook Is Nothing Then Set oBook = Nothing End If If Not xlWB Is Nothing Then xlWB.Save xlWB.Close Set xlWB = Nothing End If If Not xlApp Is Nothing Then xlApp.Quit Set xlApp = Nothing End If DoCmd.SetWarnings True MsgBox ("INVENTORY SHEET HAS BEEN CREATED.") End Sub 

尝试这个:

 LastRowInventory = ActiveSheet.Range("B" & Rows.Count).End(xlUp).Row 

或者,如果这不起作用尝试:

 LastRowInventory = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row 

这对你有帮助吗?

编辑:

 LastRowInventory = InventoryListSheet.Range("A" & InventoryListSheet.Rows.Count & "").End(xlUp).Row 

通过指定要计算行的表单问题是固定的。