none
Import csv timephased data into ms-project RRS feed

  • Question

  • Hi everyone! I'm trying to import timephased data from a csv file into ms-project, but its much more difficulty than I thought.

    I've read tons of information on the web and the only one which helped little to resolve it was at https://msdn.microsoft.com/en-us/library/ee355231(v=office.12).aspx. BTW, I bought this book, n im still waiting to get.

    I have a csv file exported from a project management web system, which I can put all the data that project needs. 

    On this case, I'm thinking to use to import into project: 

    task name 
    resourse name 
    actual work 
    date (actual work date) 

    I could put others datas like IDs or WBS code if necessary.

    I'm trying to figure out vba programming but if anyone can help me I would be very thankfull. 

    Tks in advance
    André Leite

    Friday, May 22, 2015 9:39 PM

All replies

  • Basically i'm thinking to do like that:

    1. open csv file

    2. read csv file

    3. write on ms-project the csv data

    Friday, May 22, 2015 9:42 PM
  • Hi,

    All the code you need is in the book you're waiting to arrive.

    You can either import the data in VBA directly from the csv file or you can open the csv file in Excel and read from there. Code is in the book for both methods.

    Reading directly from csv will be a bit faster, but need slightly more complex code.

    If the csv is comma delimited, the following code prints what's in a line to the immediate window.

    Sub Readcsv()
    Const SampleLine = """Task 1"",""2d"",$2000"
    Dim Data() As String
    Dim ind As Long
    Dim str As String
    '    Open "Csv full path" For Input As #1
    '    Line Input #1, str
        str = SampleLine    'For testing only
        str = Replace(str, """", "") 'Remove double quotes from strings
        Data = Split(str, ",") 'Split using commas
        For ind = 0 To UBound(Data)
            Debug.Print Data(ind)
        Next ind
    End Sub

    Result in Immediate window is:

    Task 1
    2d
    $2000

    Now you can red each data item from the Data array and do what you want, EG:

    Sub Readcsv()
    Const SampleLine = """Task 1"",""2d"",$2000"
    Dim Data() As String
    Dim ind As Long
    Dim str As String
    Dim Tsk As Task
    '    Open "Csv full path" For Input As #1
    '    Line Input #1, str
        str = SampleLine    'For testing only
        str = Replace(str, """", "") 'Remove double quotes from strings
        Data = Split(str, ",") 'Split using commas
        Set Tsk = ActiveProject.Tasks.Add(Data(0))
        Tsk.Duration = Data(1)
        Tsk.FixedCost = Data(2)
    End Sub
    


    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz

    Saturday, May 23, 2015 10:10 PM
    Moderator