How to check the cell contents on spreadsheet load?

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

How to check the cell contents on spreadsheet load?
 
Vanavah Edwards




Posts: 3
Joined: 2023-09-06
I created a ribbon with a specific data collection spreadsheet. However, I only want our ribbon to be visible ONLY if this spreadsheet is loaded. I can check if is loaded by the contents of cell A43 = "Spreadsheet Code". I tried the code below but it does not work. I would really appreciate it if you could help to get this done.

Private Sub AddinModule_OnRibbonLoaded(sender As Object, ribbon As IRibbonUI) Handles MyBase.OnRibbonLoaded
ws1 = ExcelApp.ActiveSheet
valx = ws1.Range("A43").Value
If valx = "Spreadsheet Code" Then
MsgBox("Hello! Please go to our AWD Ribbon")
AdxRibbonTab1.Visible = True
Else
AdxRibbonTab1.Visible = False
End If
End Sub
Posted 06 Sep, 2023 08:23:13 Top
Andrei Smolin


Add-in Express team


Posts: 19122
Joined: 2006-05-11
Hello Vanavah,

That is a wrong way. Check section Updating custom Ribbon controls at run time; see the PDF file in the folder {Add-in Express}\Docs on your development PC.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 06 Sep, 2023 08:58:16 Top
Vanavah Edwards




Posts: 3
Joined: 2023-09-06
I tried the documentation but still not working. This is the code I tried.


    '********************** HIDE/SHOW RIBBON AT RUNTIME ********************** 
    Private Sub AdxRibbonTab11_PropertyChanging(sender As Object, e As AddinExpress.MSO.ADXRibbonPropertyChangingEventArgs) Handles AdxRibbonTab1.PropertyChanging
        AdxRibbonTab1.Visible = False
        Dim ws1 As Excel.Worksheet
        Dim valx as string = ""
        Try
            ws1 = ExcelApp.ActiveSheet
            valx = ws1.Range("A43").Value.ToString
            If valx = "Spreadsheet Code" Then
                MsgBox("Hello!  Please go to our AWD Ribbon")
                AdxRibbonTab1.Visible = True
            End If
        Catch ex As Exception
            AdxRibbonTab1.Visible = False
        End Try
    End Sub


Can you please point me in the right direction>
Posted 06 Sep, 2023 10:53:27 Top
Andrei Smolin


Add-in Express team


Posts: 19122
Joined: 2006-05-11
Hello Vanavah,

Vanavah Edwards writes:
I tried the documentation but still not working


The manual says:
That event occurs when the Ribbon expects that you can supply a new value for a property of the Ribbon control: Caption, Visible, Enabled, Tooltip, etc.


Your code doesn't care whether Office seeks for a new value for Caption, Visible etc.

Compare your code with the sample code that section demonstrates.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 06 Sep, 2023 11:59:36 Top
Vanavah Edwards




Posts: 3
Joined: 2023-09-06
I bought this program a few days ago and I am new to it. I wanted to hide my ribbon when my spreadsheet is not loaded and make it visible when it is loaded. I have things I can check for like the contents of specific cells e.g. A43 or the file name. I do not know how to do this in Add-In Express. Can please you point me to someone who can help me and will gladly pay for help?
Posted 06 Sep, 2023 12:57:42 Top
Andrei Smolin


Add-in Express team


Posts: 19122
Joined: 2006-05-11
Hello Vanavah,

Vanavah Edwards writes:
I do not know how to do this in Add-In Express.


You do this using the Excel object model, not in Add-in Express. The hierarchy of the Excel object model has the Excel.Application object on its top. That object is provided to you via the ExcelApp property.

Vanavah Edwards writes:
I wanted to hide my ribbon when my spreadsheet


I expected that you check the code sample and description provided in that section of the manual.

To achieve your goal, you handle the PropertyChanging event of your tab. The event is triggered whenever Office allows you change a single property of you Ribbon tab. The event handler allows you to find out the property that Office expects you to change. You use the event handler to provide Office with a new value of that property. You'll find examples of how to check the property and how to provide a new value of that property in section "Updating custom Ribbon controls at run time"; see the PDF file in the folder {Add-in Express}\Docs on your development PC.

I also recommend that you split yout task in two: use a Boolean variable to debug your code in the PropertyChanging event that shows/hides the tab. When the code is debugged, start checking the value of the cell. To simplify debugging this code, check the selected cell in the Click event of a test Ribbon button. When this code is debugged, move it to the PropertyChanging event.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 07 Sep, 2023 09:39:19 Top