Excel进程未关闭,代码每秒运行一次
我有一些命令按钮,可以将access表发送到excel电子表格,并进行一些格式化和在其中输入一些公式。其他命令按钮可以工作,但此按钮位于Excel进程未关闭,代码每秒运行一次,excel,ms-access,vba,Excel,Ms Access,Vba,我有一些命令按钮,可以将access表发送到excel电子表格,并进行一些格式化和在其中输入一些公式。其他命令按钮可以工作,但此按钮位于lastrowninventory行 我确信这与oBook有关,但我不太清楚如何修复它。我认为这是因为它试图得到一个它已经得到的对象。它每秒都会平稳运行,但不会关闭excel进程。在过去的几个小时里,我试图解决这个问题的努力没有奏效 我得到的错误如下: Run-time error '462': The remote server machine does no
lastrowninventory
行
我确信这与oBook有关,但我不太清楚如何修复它。我认为这是因为它试图得到一个它已经得到的对象。它每秒都会平稳运行,但不会关闭excel进程。在过去的几个小时里,我试图解决这个问题的努力没有奏效
我得到的错误如下:
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
通过指定要在问题上计数的行的工作表是固定的 当我试图通过复制您的代码来重新创建问题时,是否收到相同的错误?InventoryListSheet.Range(“B”和Rows.Count).End(xlUp).Row也会收到相同的错误。我的运行很好,没有任何错误。你有更相关的细节吗?让我们看看。