I have situation where I am employing a custom task pane in conjunction with a command ribbon:
The task pane is correctly presented when I execute the New or Open buttons, however I need to suppress additional task pain instances when execute the Load button. The load button is just supposed to populate the existing task pane with the header content from a .csv file. This works as expected until I execute the Apply button on the task pane. The code underneath the Apply button generates a new WorkBook, and updates some range content. Now when I execute Load, a new task pane instance is presented and the .CSV header content is loaded into this task pane instead of the original. I need to prevent this 2nd task pane instance from happening. Below is the code executed by the command buttons I refer to:
From the command ribbon:
Private Async Sub btnSubstationLoad_Click(sender As Object, e As RibbonControlEventArgs) Handles btnSubstationLoad.Click
'Load the csv file so that we can obtain the substation name
Dim fDialog As New OpenFileDialog
Dim path As String = Nothing
Try
SetTaskPaneOpen()
If fDialog.ShowDialog() = DialogResult.OK Then
path = fDialog.FileName
End If
Globals.ThisAddIn.StatusBarUpdate("Loading substation data. Please wait...")
Globals.ThisAddIn.LoadCSV(path)
Globals.ThisAddIn.CsvPath = path
Globals.ThisAddIn.SubstationName = Globals.ThisAddIn.Substations(0).Location
Globals.ThisAddIn.SubstationAlias = Globals.ThisAddIn.Substations(0).SubAlias
Globals.ThisAddIn.INN = Globals.ThisAddIn.Substations(0).INN
Globals.ThisAddIn.LicenceArea = Globals.ThisAddIn.Substations(0).LicenceArea
'Store the relevant substation alias, INN and Substation Name
'populate the substation detail fields with this information
Globals.ThisAddIn.UcSpenTagManager.txtSubstationName.Text = Globals.ThisAddIn.SubstationName
Globals.ThisAddIn.UcSpenTagManager.txtLicenceArea.Text = Globals.ThisAddIn.LicenceArea
If Globals.ThisAddIn.SubstationType = "Secondary" Then
Globals.ThisAddIn.UcSpenTagManager.rbSecondary.Checked = True
End If
If Globals.ThisAddIn.UcSpenTagManager.rbPrimary.Checked Then
Globals.ThisAddIn.UcSpenTagManager.txtUniqueSubstationId.Text = Globals.ThisAddIn.INN
Else
Globals.ThisAddIn.UcSpenTagManager.txtUniqueSubstationId.Text = Globals.ThisAddIn.SubstationAlias
End If
'Now set the file loaded flag
Globals.ThisAddIn.FileLoaded = True
'Force a delay so that the user can see the change to the status bar
Await Task.Delay(3000)
Globals.ThisAddIn.StatusBarUpdate("Ready")
Catch ex As Exception
'Now set the file loaded flag
Globals.ThisAddIn.FileLoaded = False
Throw
End Try
End Sub
From the Apply button on the Task Pane:
Private Sub btnApply_Click(sender As Object, e As EventArgs) Handles btnApply.Click
Dim wb As Workbook
Dim excelName As Excel.Name
Dim instanceFolder As String
Dim instanceTime As String = dtpTimeOfChange.Value.ToString(Globals.ThisAddIn.PatternTimeFormat)
Dim filePart As String = instanceTime & "_" &
Me.txtChangeReference.Text & "_" &
Me.txtUniqueSubstationId.Text & "_" &
_utl.SafeFileName(Me.txtSubstationName.Text, " ") & "_" &
Me.txtVoltageLevel.Text
instanceFolder = Me.txtFilePath.Text & "" &
instanceTime & "_" &
Me.txtChangeReference.Text & "_PIAttributeBatchUpdate" & "" & filePart
'Generate the tag management folder structure underneath the specified working folder
'if it doesn't already exist
'<yyyyMMdd_hhmm>_<SBM Reference>_<busbar number>_<substation name>_<voltage>
If Not Directory.Exists(instanceFolder) Then
Directory.CreateDirectory(instanceFolder)
End If
Globals.ThisAddIn.InstanceFolder = instanceFolder
'Now copy the file into place and open in Excel
File.Copy(Globals.ThisAddIn.TemplatePath, instanceFolder & "" & filePart & ".xlsm")
'If CSV file has been loaded then clone the file in the instance folder
If Globals.ThisAddIn.CsvPath <> "" Then
_utl.CloneFile(Globals.ThisAddIn.CsvPath, instanceFolder & "" & filePart & ".csv")
'Update the csv path to the new file name so that the correct reference is delivered to the template
Globals.ThisAddIn.CsvPath = instanceFolder & "" & filePart & ".csv"
End If
Dim xlb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim rng As Excel.Range
xlb = Globals.ThisAddIn.Application.Workbooks.Open(instanceFolder & "" & filePart & ".xlsm", True)
If rbPrimary.Checked Then
Globals.ThisAddIn.SubstationType = "Primary"
Else
Globals.ThisAddIn.SubstationType = "Secondary"
End If
rng = _utl.GetNamedRange("TagConvention", xlb.Names)
rng.Value = Globals.ThisAddIn.TagConvention
rng = _utl.GetNamedRange("SubstationType", xlb.Names)
rng.Value = Globals.ThisAddIn.SubstationType
'add rng updates for ExportPath, BatchPath, Voltage, License Area and
rng = _utl.GetNamedRange("CsvPath", xlb.Names)
rng.Value = Globals.ThisAddIn.CsvPath
rng = _utl.GetNamedRange("ExportPath", xlb.Names)
rng.Value = _utl.SplitPath(Globals.ThisAddIn.ExportPath, 0)
rng = _utl.GetNamedRange("BatchPath", xlb.Names)
rng.Value = _utl.SplitPath(Globals.ThisAddIn.BatchPath, 0)
rng = _utl.GetNamedRange("Voltage", xlb.Names)
rng.Value = Globals.ThisAddIn.Voltage
rng = _utl.GetNamedRange("LicenseArea", xlb.Names)
rng.Value = Globals.ThisAddIn.LicenceArea
End Sub
Kind Regards
Paul.