Sorting an Excel object in Visio using a macro (VBA) - Stack Overflow

Currently trying to use the following function to sort some data in a Visio Excel OLE Object. I have co

Currently trying to use the following function to sort some data in a Visio Excel OLE Object. I have confirmed that it can Select the Range (the line before sort), and it is correctly selecting all the data I an trying to sort. As soon as the next line runs (xlSheet.Range.Sort) I get a "Error 1004: Sort method of Range class failed".

I have tried:

  1. Checking with Copilot
  2. Checking Stack (I have spelt Ascending correctly heh)
  3. Opening the excel object from Visio, which opens Excel, then adding a macro to sort the data, which works fine
  4. Tried sorting just column B (B2:B17) with the same error
  5. Tried including headers, didn't make a diff.

But I can't get this error to resolve

Dim xlApp As Object
Dim xlSheet As Object
Dim visPage As Visio.Page
Dim CList As Object

' Get the currently selected Visio page
Set visPage = Visio.ActiveWindow.Page

' Get the Excel object from the Visio page
Set CList = ActivePage.OLEObjects("Cable List").Object

' Get the Excel application and sheet
Set xlApp = CList.Application
Set xlSheet = CList.Sheets(1)

' Sort the range B2:E17 by column B
xlSheet.Range("B2:E17").Select
xlSheet.Range("B2:E17").Sort Key1:=xlSheet.Range("B2"), Order1:=xlAscending, Header:=xlNo

' Do something with the Visio page (e.g., refresh or update)
visPage.Refresh

' Clean up
Set xlSheet = Nothing
Set xlApp = Nothing
Set CList = Nothing

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743739619a4498895.html

相关推荐

  • Sorting an Excel object in Visio using a macro (VBA) - Stack Overflow

    Currently trying to use the following function to sort some data in a Visio Excel OLE Object. I have co

    6天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信