Guild of Project Controls: Compendium | Roles | Assessment | Certifications | Membership

Tips on using this forum..

(1) Explain your problem, don't simply post "This isn't working". What were you doing when you faced the problem? What have you tried to resolve - did you look for a solution using "Search" ? Has it happened just once or several times?

(2) It's also good to get feedback when a solution is found, return to the original post to explain how it was resolved so that more people can also use the results.

change data in excel with links/objects

4 replies [Last post]
John Smitt
User offline. Last seen 17 years 43 weeks ago. Offline
Joined: 30 Jan 2005
Posts: 38
I’m sure there is a way from Ms project to change data in Excel from project. Ive been doing it manually and much of the data are spreadsheets with plan based data.
I’d like to create an object on a plan milestone to a cell in Excel. When I change the plan, Excel is automatically changed.
any ideas?

Replies

richard perry
User offline. Last seen 12 years 7 weeks ago. Offline
Joined: 30 Jul 2003
Posts: 4
Groups: None
This can be done with vba, but even then you have to manually run the macro.

Here’s some vba code that shows you how to talk to Excel from project. You should be able to work out what it is doing. It is the basic structure of how to do this cleanly and reliably that is important here. Get this basic code working and you can do most anything in Excel from a MS Project macro.




Sub WriteDataToExcel()

’This is a test macro to write data from project to a new
’instance of an MS Excel file.

’ Declare an object variable to hold the object
’ reference. Dim as Object causes late binding.

Dim ExcelSheet As Object
Set ExcelSheet = CreateObject("Excel.Sheet")

’This code starts the application creating the object, in this case, a Microsoft Excel spreadsheet. Once an object is created, you reference it in code using the object variable you defined. In the following example, you access properties and methods of the new object using the object variable, ExcelSheet, and other Microsoft Excel objects, including the Application object and the Cells collection.

’ Make Excel visible through the Application object.
ExcelSheet.Application.Visible = True
’ Place some text in the first cell of the sheet.
ExcelSheet.Application.Cells(1, 1).Value = "This is column A, row 1"

Dim RowNumber As Integer

RowNumber = 3
For Each t In ActiveProject.Tasks ’ loop sequentially through all the tasks in the project

ExcelSheet.Application.Cells(RowNumber, 1).Value = t.Name
ExcelSheet.Application.Cells(RowNumber, 2).Value = t.Start
ExcelSheet.Application.Cells(RowNumber, 3).Value = t.Number1
RowNumber = RowNumber + 1

Next t

’===

’ Save the sheet to C:\test.xls directory.
ExcelSheet.SaveAs "C:\TEST.XLS"
’ Close Excel with the Quit method on the Application object.
ExcelSheet.Application.Quit
’ Release the object variable.
Set ExcelSheet = Nothing


End Sub
Zhang Haixiang
User offline. Last seen 3 years 44 weeks ago. Offline
Joined: 14 Apr 2005
Posts: 250
Groups: None
yes it is not a reliable way.
if you have a big amount of data,you can try to save your .mpp as Access database (.mdb),then make query in excel.

or make it simple,just do what you want in Access.
John Smitt
User offline. Last seen 17 years 43 weeks ago. Offline
Joined: 30 Jan 2005
Posts: 38
Thanks, i tried this but it seems to take ages to open or pretty much do anything and also crashes all the time.
Does project need installing again? (msp 2000)
Zhang Haixiang
User offline. Last seen 3 years 44 weeks ago. Offline
Joined: 14 Apr 2005
Posts: 250
Groups: None
copy cell in ms-project, and paste special (link) in Excell