Posts 1 - 10 of 18
First | Prev. | 1 2 | Next | Last
|
|
Leon Lai Kan
Posts: 200
Joined: 2018-12-20
|
Hi,
I am studying this download:
How to show and hide Excel Task Panes programmatically
https://www.add-in-express.com/support/vb-net-excel.php
In this sample, we create a button (called adxRibbonButton1, caption = ShowADXExcelTaskPane1) on the ribbon.
When we click on the button, the Task Pane (ADXExcelTaskPane1) appears.
In the AddinModule.vb, there is this sub:
Public Sub UpdateButton()
Dim TaskPane As AddinExpress.XL.ADXExcelTaskPane = AdxExcelTaskPanesCollectionItem1.TaskPaneInstance
If Sample.ExcelUtils.Version = Sample.ExcelUtils.HostVersion.v2007 Then
If TaskPane IsNot Nothing Then
adxRibbonButton1.Enabled = Not TaskPane.Visible
Else
adxRibbonButton1.Enabled = True
End If
Else
If TaskPane IsNot Nothing Then
Sample.ADXUtils.SetEnablePropertyOfCommandBarButton(CommandBarButton, Not TaskPane.Visible)
Else
Sample.ADXUtils.SetEnablePropertyOfCommandBarButton(CommandBarButton, True)
End If
End If
End Sub
I understand the logic as follows:
If the Excel version is 2007 (ribbon version)
If TaskPane IsNot Nothing Then
red
Else
blue
End If
If the Excel version < 2007 (command bar version)
etc, etc
----
I have some difficulty to understand what the code in red means:
-----
Else
If TaskPane Is Nothing Then
blue
I understand this to mean: If TaskPane does not exist, enable the adxRibbonButton1
red
---------
If TaskPane IsNot Nothing Then
red
What does this code mean? Does it mean:
If TaskPane exists, enable the adxRibbonButton1 and make the task pane invisible (i.e not embedded)?
red
Thanks
Leon
red
Is it possible to attach an image (.jpg) which is found on my computer to this message? |
|
Posted 25 Jan, 2019 07:06:24
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
Leon Lai Kan writes:
If Sample.ExcelUtils.Version = Sample.ExcelUtils.HostVersion.v2007 Then
The assumption above is: there's only one Ribboned Excel version, namely 2007.
Leon Lai Kan writes:
I have some difficulty to understand what the code in red means:
You refer to adxRibbonButton1.Enabled = Not TaskPane.Visible. This enables or disables the button depending on what the TaskPane.Visible property returns: the button is disabled if the task pane is visible.
Leon Lai Kan writes:
I understand this to mean: If TaskPane does not exist, enable the adxRibbonButton1
Seems strange?
Why strange? I suppose that button creates a new pane instance or shows/hides an existing one. If so, that code says: "enable the button if there's no task pane instance".
Leon Lai Kan writes:
If TaskPane IsNot Nothing Then adxRibbonButton1.Enabled = Not TaskPane.Visible
What does this code mean? Does it mean: If TaskPane exists, enable the adxRibbonButton1 and make the task pane invisible (i.e not embedded)?
I know this does not make sense. So, what does this line of code mean?
It means: If TaskPane exists, set the adxRibbonButton1.Enabled property depending on the TaskPane.Visible property: the button is enabled if the task pane is invisible.
Leon Lai Kan writes:
Is it possible to attach an image (.jpg) which is found on my computer to this message?
It isn't possible to attach it. You should put it on a web server and use the IMG button above the Reply Form.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 25 Jan, 2019 08:29:15
|
|
Top
|
|
Leon Lai Kan
Posts: 200
Joined: 2018-12-20
|
Hi, Andrei
Your reply gave me a great insight!
Now, I understand this line clearly (and many of your other samples also have this kind of code):
If TaskPane IsNot Nothing Then
adxRibbonButton1.Enabled = Not TaskPane.Visible
As you said, it means:
If TaskPane exists, then:
If it is invisible, enable ribbon button1
If it is visible, disable ribbon button1.
My reasoning goes like this:
If the TaskPane is invisible, RHS of the equation (Not TaskPane.Visible) returns True
The LHS (adxRibbonButton1.Enabled) is therefore set to True.
This means the ribbon button 1 is enabled.
etc...
Thanks a lot!
---------------------------------------------------------------------------------------------------------------
If Sample.ExcelUtils.Version = Sample.ExcelUtils.HostVersion.v2007 Then
The assumption above is: there's only one Ribboned Excel version, namely 2007.
I use Excel version 2016 instead of 2007.
red
Public Class ExcelUtils
Public Enum HostVersion
vUnknown = 0
v2000 = 9
v2002 = 10
v2003 = 11
v2007 = 12
End Enum
--------------------------------------------------------------------------------------------------------------
Could you give me an indication how I can set up a web server (free if possible) on my computer, and use it to upload images with the IMG button? No idea at all!
Best Regards,
Leon |
|
Posted 26 Jan, 2019 01:50:51
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
Hello Leon,
I would use
If Me.HostMajorVersion > 11 Then
Where:
- Me stands for the add-in module in which the code line is executed; if that code isn't in the add-in module, replace Me with {your add-in namespace e.g. MyAddin1}.AddinModule.CurrentInstance.
- 11 stands for Office 2003.
Leon Lai Kan writes:
Could you give me an indication how I can set up a web server (free if possible) on my computer, and use it to upload images with the IMG button? No idea at all!
Oh, no! This isn't about installing something on your machine. You should use a free public web server to store files that can be accessed over the web. I've met references to Google drive, Microsoft OneDrive, Dropbox, etc.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 28 Jan, 2019 04:04:11
|
|
Top
|
|
Leon Lai Kan
Posts: 200
Joined: 2018-12-20
|
Andrei,
Thanks a lot for your very useful information.
I have one more question on the same sample.
In ADXExcelTaskPane1.vb, we have this Sub:
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
Me.Hide()
TryCast(AddinModule, AddinModule).UpdateButton()
End Sub
I often meet TryCast() in your samples. So, I must master this concept.
I did some search:
TryCast (Object As Expression, Object As Type) As Object
----
The 1st AddinModule returns the add-in module:
AddinExpress.XL > ADXExcelTaskPane > AddinModule
----
The 2nd AddinModule refers to the class AddinModule
----
red
NB: UpdateButton() is found in AddinModule.vb
Leon |
|
Posted 28 Jan, 2019 06:03:34
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
Hello Leon,
Instead, use the following construct:
{your add-in namespace e.g. MyAddin1}.AddinModule.CurrentInstance.UpdateButton
The code line that you refer to casts the AddinModule property of the pane (it returns an ADXAddinModule) to {your add-in namespace e.g. MyAddin1}.AddinModule.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 28 Jan, 2019 06:53:42
|
|
Top
|
|
Leon Lai Kan
Posts: 200
Joined: 2018-12-20
|
Andrei,
{your add-in namespace e.g. MyAddin1}.AddinModule.CurrentInstance.UpdateButton
I tried:
VisibilityAETPVs2005vb.AddinModule.CurrentInstance.
I can go only that far. IntelliSense does not detect "UpdateButton".
If I Type "UpdateButton", I get this error message:
UpdateButton is not a member of 'AddinExpress.MSO.ADXAddinModule'
red
Nb: The code is in ADXExcelTaskPane1.vb , whereas UpdateButton() is in AddinModule.vb
Leon |
|
Posted 28 Jan, 2019 07:31:13
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
Hello Leon,
If you open the propertis of the project, you'll find that the Root Namespace (on the Application tab) contains adx_xl_vb_taskPaneVisibility.
adx_xl_vb_taskPaneVisibility.AddinModule.CurrentInstance.UpdateButton()
Andrei Smolin
Add-in Express Team Leader |
|
Posted 28 Jan, 2019 08:27:59
|
|
Top
|
|
Leon Lai Kan
Posts: 200
Joined: 2018-12-20
|
Hi, Andrei
Got it!
Thanks for your patience.
Leon |
|
Posted 28 Jan, 2019 08:51:02
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
You are welcome!
Andrei Smolin
Add-in Express Team Leader |
|
Posted 28 Jan, 2019 09:22:50
|
|
Top
|
|
Posts 1 - 10 of 18
First | Prev. | 1 2 | Next | Last
|