Questions about a Blog Article

Add-in Express™ Support Service
That's what is more important than anything else

Questions about a Blog Article
Working with Excel tables & ranges 
Leon Lai Kan




Posts: 200
Joined: 2018-12-20
Hi, Andrei

I am now studying this blog sample:
Working with Excel tables & ranges
https://www.add-in-express.com/creating-addins-blog/2013/10/24/excel-tables-ranges-vbnet/

This sample (meant for beginners!) appears very interesting, but unfortunately it does not contain any buttons which we can click to see what happens. It is not self working!

So, I must create all the necessary buttons to call the action Subs.

I will try. But do you think it's easy for beginners?

The blog is rather dated (October 2013) and I would suggest that your Add-In Express team updates the sample so that it is self-working (complete with buttons) and can serve as good learning material!

If you could do that within the next few days, it would be a great, great, great help for me! And other beginners too!

Thanks in advance.

But in the meantime, Andrei, I may have to bother you to help me creating the buttons (which work!) :)


Best Regards,
Leon


=================================================================================================

So, here is my first problem:

I created a button (SortTbl) which calls the Sub SortTable.


Private Sub SortTbl_OnClick(ByVal sender As System.Object, _
ByVal control As AddinExpress.MSO.IRibbonControl, _
ByVal pressed As System.Boolean) Handles SortTbl.OnClick

        Dim Mysheet As Excel.Worksheet = TryCast(ExcelApp.ActiveSheet, Excel.Worksheet)
        Dim MytableName As String = "tabName"
        Dim sortyBy As Excel.Range = Nothing

        SortTable(Mysheet, MytableName, sortyBy)

    End Sub


Private Sub SortTable(sheet As Excel.Worksheet, _
        tableName As String, sortyBy As Excel.Range)

        sheet.ListObjects(tableName).Sort.SortFields.Clear()
        sheet.ListObjects(tableName).Sort.SortFields.Add( _
            sortyBy, Excel.XlSortOn.xlSortOnValues)
        With sheet.ListObjects(tableName).Sort
            .Header = Excel.XlYesNoGuess.xlYes
            .MatchCase = False
            .SortMethod = Excel.XlSortMethod.xlPinYin
            .Apply()
        End With
    End Sub



I created a table with 2 columns and a few rows by clicking on the Create Table button in the add-in.

When I click on the button SortTbl, the table is not sorted, but the add-in crashes.

red


Thanks
Leon
Posted 27 Feb, 2019 10:54:48 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Hello Leon,

I must confess that you are the very first programming beginner; there are no other beginners. The article is for beginners in Excel programming, not in programming itself.

I don't think we will be able to update it any time soon as we have plans, priorities and resources.

So, yes, you should create buttons to invoke the test methods.

Leon Lai Kan writes:
Please tell me where my code (for the button OnClick) is wrong.


You should debug your code to find the code line that causes the crash and extract extra details (if they are) required to identify the issue. For instance, check https://www.homeandlearn.co.uk/NET/nets5p6.html.


Andrei Smolin
Add-in Express Team Leader
Posted 28 Feb, 2019 06:43:58 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Hello Leon,

Thank you for your honest feedback, we appreciate it. We have deleted your last message as requested.

My suggestion to debug the project is still applicable.


Andrei Smolin
Add-in Express Team Leader
Posted 28 Feb, 2019 09:17:28 Top