Addin to MS Project

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
 
J

Jack Dahlgren

How about moving the code before making the app visible> Perhaps it is
changing the focus.

-Jack
 
M

Mask

It doesn't work either,

I need to have "xl.Application.Visible = true" right after creating
excel or it will not open excel.
In another hand I still can't make it to add workbook and worksheet...
I don't make any idea what I'm doing wrong...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top