locked
Project Professional 2010 - how to use TimelineExport from Powershell RRS feed

  • Question

  • I'm trying to export the timeline using the new TimelineExport method in Project 2010 VBA.  I'd like to paste it into a Word doc.

    I've got winproj 2010 and office 2010.  Here's the Powershell script.    I'm able to paste but I can't paste the timeline :)

    You may need to run this with the -sta switch.

    $msproject = New-Object -ComObject MSProject.Application
    $msproject.Visible = $true
    $msproject.FileOpen( "c:\gstest1.mpp") # replace with your test file
    $a = $msproject.TimelineExport
    
    if ($a)
    {
    
    $msword = New-Object -ComObject Word.Application
    $msword.Visible = $true
    $objDoc = $msword.Documents.Add()
    $objSelection = $msword.Selection
    $objSelection.PasteAndFormat( $wdPastePicture )
    }
    
    Thursday, July 22, 2010 10:36 PM

Answers

  • Rod --

    That didn't quite do the trick and it's VBA, we're in Powershell world. :)  A colleague working with me had to experiment and we came up with this Powershell solution that works.  The trick seemed to be .ViewApply("Timeline").  The following Powershell script will take an MPP file, export the timeline onto a landscape legal page in MSWord.

     function Copy-Timeline([String]$FileName)
    {
        begin
        {
            $proj = New-Object -ComObject MSProject.Application
            $word = New-Object -ComObject Word.Application
        }
        process
        {
            $proj.FileOpen( $FileName )
           
            $proj.ViewApply("Timeline")
            $proj.TimelineExport(0, 1318) #first param determines how much of the timeline is copied.  2nd param is size of copy.  1318 is about right for legal with .25" margins.
            $proj.FileClose(0) #guessed that "0" = do not save

           
           
           
            $doc = $word.Documents.Add()
            $doc.PageSetup.PaperSize = 4 # 4 = Legal
            $doc.PageSetup.Orientation = 1 # 1 = landscape, 0 = portrait
            $doc.PageSetup.LeftMargin = 25
            $doc.PageSetup.RightMargin = 25
            $doc.PageSetup.TopMargin = 50
            $doc.PageSetup.BottomMargin = 50
           
            $sel = $word.Selection
            $sel.PasteAndFormat( 16 ) #16 = wdFormatOriginalFormatting
            $word.Visible = $true
           
           
        }
        end
        {
            $proj.FileExit( 0 ) #0 = do not save
        }
       
    }

    Copy-Timeline "c:\test.mpp"

     

    • Marked as answer by Glenn Scott Monday, July 26, 2010 3:10 PM
    Monday, July 26, 2010 3:09 PM

All replies

  • Hi,
     
    You may need to activate the timeline view before making the call. I got away without doing this once, but not the next time I tried!
     
    Use:
    WindowActivate TopPane:=False

    --

    Rod Gill
    Microsoft MVP for Project - http://www.project-systems.co.nz
     
    Author of the only book on Project VBA, see: http://www.projectvbabook.com
     

     
    "Glenn Scott" wrote in message news:62e96819-d9ec-4715-bfb0-39a479697a19...

    I'm trying to export the timeline using the new TimelineExport method in Project 2010 VBA.  I'd like to paste it into a Word doc.

    I've got winproj 2010 and office 2010.  Here's the Powershell script.    I'm able to paste but I can't paste the timeline :)

    You may need to run this with the -sta switch.

    $msproject = New-Object -ComObject MSProject.Application
    $msproject.Visible = $true
    $msproject.FileOpen( "c:\gstest1.mpp") # replace with your test file
    $a = $msproject.TimelineExport
    
    if ($a)
    {
    
    $msword = New-Object -ComObject Word.Application
    $msword.Visible = $true
    $objDoc = $msword.Documents.Add()
    $objSelection = $msword.Selection
    $objSelection.PasteAndFormat( $wdPastePicture )
    }
    


    __________ Information from ESET Smart Security, version of virus signature database 5304 (20100723) __________

    The message was checked by ESET Smart Security.

    http://www.eset.com

    The one and only Project VBA Book Rod Gill Project Management
    Friday, July 23, 2010 11:05 AM
  • Rod --

    That didn't quite do the trick and it's VBA, we're in Powershell world. :)  A colleague working with me had to experiment and we came up with this Powershell solution that works.  The trick seemed to be .ViewApply("Timeline").  The following Powershell script will take an MPP file, export the timeline onto a landscape legal page in MSWord.

     function Copy-Timeline([String]$FileName)
    {
        begin
        {
            $proj = New-Object -ComObject MSProject.Application
            $word = New-Object -ComObject Word.Application
        }
        process
        {
            $proj.FileOpen( $FileName )
           
            $proj.ViewApply("Timeline")
            $proj.TimelineExport(0, 1318) #first param determines how much of the timeline is copied.  2nd param is size of copy.  1318 is about right for legal with .25" margins.
            $proj.FileClose(0) #guessed that "0" = do not save

           
           
           
            $doc = $word.Documents.Add()
            $doc.PageSetup.PaperSize = 4 # 4 = Legal
            $doc.PageSetup.Orientation = 1 # 1 = landscape, 0 = portrait
            $doc.PageSetup.LeftMargin = 25
            $doc.PageSetup.RightMargin = 25
            $doc.PageSetup.TopMargin = 50
            $doc.PageSetup.BottomMargin = 50
           
            $sel = $word.Selection
            $sel.PasteAndFormat( 16 ) #16 = wdFormatOriginalFormatting
            $word.Visible = $true
           
           
        }
        end
        {
            $proj.FileExit( 0 ) #0 = do not save
        }
       
    }

    Copy-Timeline "c:\test.mpp"

     

    • Marked as answer by Glenn Scott Monday, July 26, 2010 3:10 PM
    Monday, July 26, 2010 3:09 PM