PDA

View Full Version : Export FROM Excel TO MS Project 2007



Drivium
01-23-2013, 02:34 PM
I'm trying to do something similar as described in this thread:
h
t
t
p
:
//ww
w.
vbaexpress
.com/
forum/
archive/
index
.php/t-5276
.html

But I am not clear on how to apply this (or if it totally applies to my case). Simply put, I have a few columns/rows of cells with headers that I need to export into MS Project. I would like to automate this process. I have an existing project file template I intend to use called Forecast_2013.mpp.

For example, in Excel I have these headers (starting on A1):
Rig Well Comment Duration Start_Date Predecessors

Each of those have data under them. I just need to get this into Excel. Forgive me for my poor explanation... I'm pretty sure if I tweaked the code from the other thread, it would do exactly what I need...just not sure what to tweak...

If it helps, the name of my spreadsheet is Forecast_2013.xls and the specific sheet in the workbook is called Task_Table1

Sorry for the weird link - it's a link to THIS forum...but wouldn't allow it.
TIA

Drivium
01-23-2013, 03:48 PM
Ok - made some progress with this:

Option Explicit
Sub Add_Data_Project()
'Add a reference to Microsoft Project x.x Object Library
'in the VB-editor through the command Tools | References..
'The x.x stands for version like 11.0 or previously.
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim stRig As String, stWell As String, stComment As String
Dim lnDuration As Long
Dim dtStart As Date
Set wbBook = ThisWorkbook
Set wsSheet = wbBook.Worksheets(1)
'Populate the variables with values from the worksheet.
With wsSheet
stRig = .Range("A2:A40")
stWell = .Range("B2").Value
stComment = .Range("C2").Value
lnDuration = .Range("K2").Value
dtStart = .Range("L2").Value
End With
'Instantiate and open MS Project and the project.
Dim prApp As MSProject.Application
Dim prProject As MSProject.Project
Set prApp = New MSProject.Application
prApp.FileOpen "Forecast_2013.mpp"
Set prProject = prApp.ActiveProject
'Add task and other wanted information to the project.
With prProject
.Tasks.Add stRig
.Tasks.Add stWell
.Tasks.Add stComment
.Tasks.Add lnDuration
.Tasks.Add dtStart
With .Tasks(stRig)
.Text1 = stRig
.Text2 = stWell
.Text4 = stComment
.Duration = lnDuration & " days"
.Start = dtStart
End With
End With
'Save the project and close MS Project.
With prApp
.FileSave
.Quit
End With
MsgBox "The project VBAX has successfully been updated!", vbInformation
'Release objects from memory.
Set prProject = Nothing
Set prApp = Nothing
End Sub

It works fine if I only include one cell in the range:
Example: stRig = .Range("A2")
However - as soon as I try: stRig = .Range("A2:A40").Value
I get a type mismatch error... can't figure it out.
Even tried: stRig = .Range("A2,A3").Value
This doesn't error and completes successfully - but only adds a single line in project, not the 2 lines I would expect..

Also, not sure what this line is: With .Tasks(stRig)
Im sure what this is for...some kind of index, but how do I use it?