M
masayoshi hayashi
I have found my add-in program cause a problem with opening a file
twice. Here is a symptom:
Click an xls file, open Excel, loads the add-in, but no worksheet.
Click the xls file again and Excel opens the file.
Clicking on Excel.exe short-cut icon results in loading the add-in and
opening a default book1 workbook.
Removing the add-in solves this problem. If you could give me some
hints or directions for solving my add-in problem, I'd be appreciated.
Below is my code in ThisWorkbook module:
----------------------------------------
Option Explicit
Dim InstalledProperly As Boolean
Dim Item As AddIn
Dim wb As Workbook
Dim AddInTitle As String
Dim Toolbar As String
Private Sub Workbook_AddinInstall()
InstalledProperly = True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call DeleteToolbar(Toolbar)
End Sub
Private Sub Workbook_Open()
Dim Msg As String
' Check user's excel version for compatibility
Call CheckVersion
If Not ThisWorkbook.IsAddin Then Exit Sub
If Not InAddInCollection(ThisWorkbook) Then
' Add it to the AddIns collection
AddIns.Add Filename:=ThisWorkbook.FullName
' Install it
AddInTitle = GetTitle(ThisWorkbook)
Application.EnableEvents = False
AddIns(AddInTitle).Installed = True
Application.EnableEvents = True
' Inform user
Msg = ThisWorkbook.Name & " has been installed as an add-in. "
Msg = Msg & "Use the Tools Add-Ins command to uninstall it. "
MsgBox Msg, vbInformation, AddInTitle
End If
Splash.Show
' Generating Toolbar
Toolbar = "CrossTab"
Call CreateToolbar(Toolbar)
Call AddButton(Toolbar, 107, "MainControl", "Generate Cross Tabs")
Call AddButton(Toolbar, 459, "Refresh", "Refresh")
Call AddButton(Toolbar, 558, "ShowUFPage", "Set Pages")
' Assigning the default value for Cancel Buttons of userforms.
CancelB = False
'Assigning help.chm file as help
' ThisWorkbook.VBProject.HelpFile = Path & "\Help.chm"
End Sub
Function InAddInCollection(wb) As Boolean
For Each Item In AddIns
If Item.Name = wb.Name Then
InAddInCollection = True
End If
Next Item
End Function
Function GetTitle(wb) As String
GetTitle = ""
For Each Item In AddIns
If Item.Name = wb.Name Then
GetTitle = Item.Title
End If
Next Item
End Function
Private Sub CheckVersion()
If Val(Application.Version) < 9 Then
MsgBox "This add-in works only with Excel 2000 or later"
ThisWorkbook.Close
End If
End Sub
twice. Here is a symptom:
Click an xls file, open Excel, loads the add-in, but no worksheet.
Click the xls file again and Excel opens the file.
Clicking on Excel.exe short-cut icon results in loading the add-in and
opening a default book1 workbook.
Removing the add-in solves this problem. If you could give me some
hints or directions for solving my add-in problem, I'd be appreciated.
Below is my code in ThisWorkbook module:
----------------------------------------
Option Explicit
Dim InstalledProperly As Boolean
Dim Item As AddIn
Dim wb As Workbook
Dim AddInTitle As String
Dim Toolbar As String
Private Sub Workbook_AddinInstall()
InstalledProperly = True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call DeleteToolbar(Toolbar)
End Sub
Private Sub Workbook_Open()
Dim Msg As String
' Check user's excel version for compatibility
Call CheckVersion
If Not ThisWorkbook.IsAddin Then Exit Sub
If Not InAddInCollection(ThisWorkbook) Then
' Add it to the AddIns collection
AddIns.Add Filename:=ThisWorkbook.FullName
' Install it
AddInTitle = GetTitle(ThisWorkbook)
Application.EnableEvents = False
AddIns(AddInTitle).Installed = True
Application.EnableEvents = True
' Inform user
Msg = ThisWorkbook.Name & " has been installed as an add-in. "
Msg = Msg & "Use the Tools Add-Ins command to uninstall it. "
MsgBox Msg, vbInformation, AddInTitle
End If
Splash.Show
' Generating Toolbar
Toolbar = "CrossTab"
Call CreateToolbar(Toolbar)
Call AddButton(Toolbar, 107, "MainControl", "Generate Cross Tabs")
Call AddButton(Toolbar, 459, "Refresh", "Refresh")
Call AddButton(Toolbar, 558, "ShowUFPage", "Set Pages")
' Assigning the default value for Cancel Buttons of userforms.
CancelB = False
'Assigning help.chm file as help
' ThisWorkbook.VBProject.HelpFile = Path & "\Help.chm"
End Sub
Function InAddInCollection(wb) As Boolean
For Each Item In AddIns
If Item.Name = wb.Name Then
InAddInCollection = True
End If
Next Item
End Function
Function GetTitle(wb) As String
GetTitle = ""
For Each Item In AddIns
If Item.Name = wb.Name Then
GetTitle = Item.Title
End If
Next Item
End Function
Private Sub CheckVersion()
If Val(Application.Version) < 9 Then
MsgBox "This add-in works only with Excel 2000 or later"
ThisWorkbook.Close
End If
End Sub