【问题标题】:Getting runtime error on refreshing listobject named range刷新名为范围的列表对象时出现运行时错误
【发布时间】:2018-08-10 15:52:49
【问题描述】:

以下是我发送邮件的代码:

Sub SendRequestForApprovalMail()

 Application.ScreenUpdating = False
 Application.StatusBar = "Step 1/2 - Retrieving your pending approvals from SharePoint..."
  Range("T_myPendingApprovals[#All]").ListObject.Refresh

 'new in v.5.0 - date format is changed as for some users the date format looks strange
   Union(Range("T_myPendingApprovals[Start]"), Range("T_myPendingApprovals[End]")).NumberFormat = "m/d/yyyy"
   Union(Range("T_myPendingApprovals[Modified]"), Range("T_myPendingApprovals[Created]")).NumberFormat = "m/d/yyyy h:mm"

 If Application.WorksheetFunction.CountA(Range("T_myPendingApprovals[Person]")) = 0 Then
  Application.StatusBar = False
  Application.ScreenUpdating = True
  MsgBox "No entries with pending approval existing for you." & vbLf & vbLf & "Your supervisor should enter his name in the column 'Approved by', not you. Only then the records will be displayed in the mail for approval.", vbExclamation, "Approval mail generation"
  End
 End If

 Application.StatusBar = "Step 2/2 - Preparing approval mail..."

 SendMail "Request for vacation approval for " & UserNameWindows, _
           "Hi ..., <br><br>" & _
          "Please approve my vacation as stated below. To evaluate potential capacity issues in the team as well as " & _
          "towards important milestones, please refresh your offine copy of the " & _
          "<a href=""" & Range("DownloadPage") & """>Team availability Tracker</a> and consider all other parallel vacations in the chart for your approval decision.<br><br>" & _
          "Please enter your name in the column approver on the " & _
          "<a href=""" & Range("ApprovalView") & """>SharePoint</a>. " & _
          "Please do not just reply on this mail, make use of the SharePoint for 100% traceability and do the update(s) there. Only if the name of the supervisor appears in the column '[last] modified by', the approval can be considered as valid. Use the voting button to indicate that the approval took place.<br><br>Best regards,<br>" & FirstName _
           , , , , Export_Range_asImage(Range("T_myPendingApprovals[#All]"))
End Sub

我在代码的最后一行收到运行时错误(应用程序定义或对象定义错误)。

 Range("T_myPendingApprovals[#All]").ListObject.Refresh

T_myPendingApprovals[#All]”在“我的待审批”工作表中被命名为范围

【问题讨论】:

  • 为什么不直接刷新列表对象的全名?
  • 你能举个例子吗? @QHarr

标签: excel vba outlook


【解决方案1】:

ListObject.Refresh 需要一个表示 ListObject 对象的变量。您将需要使用名称框中显示的对象的全名。

例如

Option Explicit

Sub GetListObjectNames()

    Dim currObject As ListObject

    For Each currObject In ActiveSheet.ListObjects

        Debug.Print currObject.Name

    Next currObject

End Sub

如果“Table1”作为名称返回

Dim myTable As ListObject
Set myTable = ActiveSheet.ListObjects("Table1") 'use actual sheet name. Don't assume Activesheet
myTable.Refresh

在你的例子中应该是这样的:

ThisWorkbook.Worksheets("my pending approvals").ListObjects("T_myPendingApprovals").Refresh

未能完成昂贵的刷新事件,例如:

ThisWorkbook.RefreshAll

【讨论】:

  • 抱歉,但刷新时仍然抛出同样的错误.. @QHarr
  • 您要刷新的表的名称是什么?这条线的错误具体是什么? Range("T_myPendingApprovals[#All]").ListObject.Refresh
  • 表名将是T_myPendingApprovals
  • 所以 ActiveSheet.ListObjects("T_myPendingApprovals").Refresh
  • @CallumDA Doh....是的...抱歉...在屏幕之间跳转...今天不是个好日子。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-03
  • 2017-04-03
  • 2014-08-17
相关资源
最近更新 更多