M
Mask
Hello Developers,
I develop an Addin but I'm having some problems with PIA's. This Addin
is directed to MS Project 2007 but I wanted to export my Data to MS
Excel 2003. After I've tried and broke my head among the references
and didn't found a solution. I'm using Visual Studio 2008
Professional. My Addin do the follow tasks:
1. Create Ms Project Toolbar;
2. Create Toolbar Button;
3. When user click button, MS Excel open
What it doesn't do:
1. I can't create workbook
2. I can't create worksheet
3. I can't export data
If the code helps:
Public Class Toolbar
Dim proj As Microsoft.Office.Interop.MSProject.Project
Dim xl As Microsoft.Office.Interop.Excel.Application
Dim commandBar As Office.CommandBar
Dim exportButton As Office.CommandBarButton
Private Sub addToolbar(ByVal barName As String)
Try
commandBar = Application.CommandBars(barName)
Catch ex As ArgumentException
End Try
If Not commandBar Is Nothing Then
Application.CommandBars(barName).Delete()
End If
Application.CommandBars.Add(barName, 1, False, False)
commandBar = Application.CommandBars(barName)
End Sub
Private Sub AddButton(ByVal CBarName As String)
commandBar = Application.CommandBars(CBarName)
Try
exportButton = CType(commandBar.Controls.Add(1),
Office.CommandBarButton)
With exportButton
.Style = Office.MsoButtonStyle.msoButtonCaption
.Caption = "Export to Excel"
.Tag = "Export to Excel"
End With
AddHandler exportButton.Click, AddressOf ExportButtonClick
commandBar.Visible = True
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ExportButtonClick(ByVal ctrl As
Office.CommandBarButton, ByRef Cancel As Boolean)
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
'Create Excel Object
xl = CType(CreateObject("Excel.Application"),
Microsoft.Office.Interop.Excel.Application)
'Show Excel
xl.Application.Visible = True
'Create workbook and worksheet
xlBook = CType(xl.Workbooks.Add,
Microsoft.Office.Interop.Excel.Workbook)
xlSheet = CType(xlBook.Worksheets(1),
Microsoft.Office.Interop.Excel.Worksheet)
'Show Worksheet
xlsheet.Application.Visible = True
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
addToolbar("Export")
AddButton("Export")
End Sub
Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Shutdown
Application.CommandBars("Export").Delete()
End Sub
End Class
I'm wondering, since Ms Project 2007 use PIA 12.0 and MS Excel use PIA
11.0 I think Visual Studio 2008 can't have references for both PIA
(which is normal).
Do I have to develop the Addin to diferent cases (eg: 1 Addin to Ms
Project 2007 that export data to Ms Excel 2007 and another Addin to MS
Project 2003 that export data to Ms Excel 2003)?
Is it possible to mix up to kinds of version (eg: 1 Addin to Ms
Project 2007 that export to Ms Excel 2003 and another Addin to MS
Project 2003 that export to Ms Excel 2007)?
I really appreciate your help,
Best Regards,
Mask
I develop an Addin but I'm having some problems with PIA's. This Addin
is directed to MS Project 2007 but I wanted to export my Data to MS
Excel 2003. After I've tried and broke my head among the references
and didn't found a solution. I'm using Visual Studio 2008
Professional. My Addin do the follow tasks:
1. Create Ms Project Toolbar;
2. Create Toolbar Button;
3. When user click button, MS Excel open
What it doesn't do:
1. I can't create workbook
2. I can't create worksheet
3. I can't export data
If the code helps:
Public Class Toolbar
Dim proj As Microsoft.Office.Interop.MSProject.Project
Dim xl As Microsoft.Office.Interop.Excel.Application
Dim commandBar As Office.CommandBar
Dim exportButton As Office.CommandBarButton
Private Sub addToolbar(ByVal barName As String)
Try
commandBar = Application.CommandBars(barName)
Catch ex As ArgumentException
End Try
If Not commandBar Is Nothing Then
Application.CommandBars(barName).Delete()
End If
Application.CommandBars.Add(barName, 1, False, False)
commandBar = Application.CommandBars(barName)
End Sub
Private Sub AddButton(ByVal CBarName As String)
commandBar = Application.CommandBars(CBarName)
Try
exportButton = CType(commandBar.Controls.Add(1),
Office.CommandBarButton)
With exportButton
.Style = Office.MsoButtonStyle.msoButtonCaption
.Caption = "Export to Excel"
.Tag = "Export to Excel"
End With
AddHandler exportButton.Click, AddressOf ExportButtonClick
commandBar.Visible = True
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ExportButtonClick(ByVal ctrl As
Office.CommandBarButton, ByRef Cancel As Boolean)
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
'Create Excel Object
xl = CType(CreateObject("Excel.Application"),
Microsoft.Office.Interop.Excel.Application)
'Show Excel
xl.Application.Visible = True
'Create workbook and worksheet
xlBook = CType(xl.Workbooks.Add,
Microsoft.Office.Interop.Excel.Workbook)
xlSheet = CType(xlBook.Worksheets(1),
Microsoft.Office.Interop.Excel.Worksheet)
'Show Worksheet
xlsheet.Application.Visible = True
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
addToolbar("Export")
AddButton("Export")
End Sub
Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Shutdown
Application.CommandBars("Export").Delete()
End Sub
End Class
I'm wondering, since Ms Project 2007 use PIA 12.0 and MS Excel use PIA
11.0 I think Visual Studio 2008 can't have references for both PIA
(which is normal).
Do I have to develop the Addin to diferent cases (eg: 1 Addin to Ms
Project 2007 that export data to Ms Excel 2007 and another Addin to MS
Project 2003 that export data to Ms Excel 2003)?
Is it possible to mix up to kinds of version (eg: 1 Addin to Ms
Project 2007 that export to Ms Excel 2003 and another Addin to MS
Project 2003 that export to Ms Excel 2007)?
I really appreciate your help,
Best Regards,
Mask