Project Standard 2010: BoxGetXPosition crashes when used for a task in a subproject RRS feed

  • Question

  • When using BoxGetXPosition to determine the position of a box (task) in a subproject, I get the following error:

    Run-time error '1004':
    An unexpected error occurred with the method.

    I'm in the Network Diagram view. The code is

    Sub BoxGetXPosition()
    	Dim tsk As MSProject.task
    	Dim XPos As Long
    	Set tsk = ActiveCell.task
    	XPos = MSProject.Application.BoxGetXPosition(tsk.ID, tsk.Project)
    	MsgBox "XPos = " & CStr(XPos)
    	Set tsk = Nothing
    End Sub

    Can anyone tell me what is wrong or how I can get around this.




    Thursday, May 24, 2012 7:07 AM

All replies

  • That works for m in Project 2010 SP1. Make sure you have the latest SP or your version of Project.

    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    Thursday, May 24, 2012 10:10 AM
  • Malcolm,

    You realize you must be in a network diagram view for the code to work properly. If you try to run if from the Gantt Chart view or the Relationship Diagram view the exact failure you describe will occur.


    Thursday, May 24, 2012 2:26 PM
  • Rod

    I have SP1 installed. The version information is: Microsoft Project 2010 (14.0.6023.1000) SP1 MSO (14.0.6112.5000)

    Any other ideas?



    Friday, May 25, 2012 1:26 PM
  • John

    I mentioned the view in my post.

    Can you think of any other setting that may cause this?



    Friday, May 25, 2012 1:40 PM
  • Malcolm,

    Yes you did. Sorry, sometimes I miss stuff.

    The other thing that comes to mind is your object library references. You should have the following references set when you view them under Tools/References in the VB Editor window:

    Visual Basic for Applications

    Microsoft Project 14.0 Object Library

    OLE Automation

    Microsoft Office 14.0 Object Library

    If you do not have all 4 of those, find the missing one(s) and set them.

    By the way, when I ran a test case I did use a dynamic master project. It doesn't matter if the active cell is part of the master or a task in one of the subprojects.


    Friday, May 25, 2012 2:44 PM