none
Ms Project pro 2016 vba programming organizermoveitem does not work RRS feed

  • Question

  • I am copying views, table filter etc from one file to global.mpt

    For all the task elements everything works fine but for resource element i get error 1001

    I have set the task parameter to false.

    Itried registering a macro and making the copy from organizer then after deleting the copied element from global executed the macro it does give me the same error.

    Here is an extract of the code I am using:

    Public Type ElementBase
        Nomfr As String
        NomEn As String
        TypeElement As Long
        Task As Boolean
      End Type

    Public Elements() As ElementBase

        For I = 1 To UBound(Elements)
            If Elements(I).TypeElement <> pjModules Then
                  OrganizerDeleteItem Type:=Elements(I).TypeElement, FileName:="Global.mpt", Name:=Elements(I).Nomfr ', Task:=Elements(I).Task

           

                OrganizerMoveItem Type:=Elements(I).TypeElement, FileName:=NomProjet, ToFileName:="Global.mpt", Name:=Elements(I).Nomfr ', Task:=Elements(I).Task

            End if

        Next I

    The instructions in the loop work perfectly for the 44 fist element the 45th one is a resource table and I get the 1001 error until I get to the 53nd element wich is a task filter and everything goes well until I get to a resource filter.

    I tried everything i can imagine and it seems it is a bug int he method itself.

    Can anybody help me.


    JBParadis

    Friday, July 21, 2017 2:10 PM

All replies

  • JBParadis,

    What is the description associated with the 1001 error?

    Also, you say you set the "Task" argument to false but I don't see that anywhere in the code snippet you show. Since Task=true is the default perhaps your code isn't set up to read any resource elements.

    John

    Sunday, July 23, 2017 10:45 PM
  • I  made a mistake the error number is 1101 and it says wrong name I checked the name and the spelleing is exactly the same as the one tha appears in the organizer.

    In my code I set the task parameter with task:=element(I).task wich is a boolean varaible containing true whent it is a task table and false when it is as resource table. I ckecked that.

    Thank for your interest in my problem


    JBParadis

    Monday, July 24, 2017 1:40 PM
  • JBParadis,

    Yeah I thought it might be error 1101 instead of 10001 since the 1001 error is usually a compiler error which means the code would not have run at all.

    There must be an error in the code you posted, since the task:=element(l).task parameter is commented out in both Organizer Method statements (note the ' just before the last parameter delimiter in both statements).

    John

    Monday, July 24, 2017 2:25 PM
  • You are right I posted the whroung code. I had put this remark to make some test. But when the remark symbol ' is removed I still get the error

    JBParadis

    Monday, July 24, 2017 3:21 PM
  • JBPardis,

    Too bad, I hoped it would be a simple fix as the erroneous comment would produce exactly what you are seeing.

    Okay, let's try a little troubleshooting. Perhaps you've done this already but if not, run the macro and when it gets to the error hover your mouse over each of the arguments in the statement (i.e. Type, Name, Task). That will show you the value of each of those arguments. Compare those values with what the value should be.

    John

    Monday, July 24, 2017 3:45 PM
  • All this has been done.

    I even tried something that you could try:

    I manualy created a new resource table that I called Test

    I made a simple procedure in VBA only using organizermoveItem

    Public Sub test()
        OrganizerMoveItem pjTables, ActiveProject.Name, "global.mpt", "test", False
    End Sub

    And tried to run the procedure I got the same problem.

    If you do the same thing but with a task table change false for true everything works fine.

    it seems the procedure organizermoveitem is not working properly.


    JBParadis

    Monday, July 24, 2017 3:55 PM
  • JBParadis,

    Are you absolutely sure the table is called "test" or is that the name of the view?

    I ran the following code and it works fine. In my case the resource view is "test" and the view table is "Table 1".

    Public Sub test()
        OrganizerMoveItem Type:=pjTables, FileName:=ActiveProject.Name, tofilename:="global.mpt", Name:="Table 1", Task:=False
    End Sub

    John

    Monday, July 24, 2017 4:33 PM
  • I am not creating any view I am just creating a resource table called test run the procedure and then check in Organizer to see if Test was copied to global.

    Are you sure your tabel 1 was not copied as a task tabel instead of a resource table.


    JBParadis

    Monday, July 24, 2017 4:55 PM
  • JBParadis,

    This is the Organizer prior to running the macro,

    And this is the Organizer after running the macro,

    This works the same whether or not the Resource view table (Table 1) is associated with a view.

    You say you create the view, run the procedure and then check the Organizer. Do you not get an error message?

    Something I forgot to ask in the beginning. Is your version of Project 2016 fully updated with the latest cumulative update?

    And just a couple other questions. Are both your file and Global on your local hard drive or are you operating over a network? Are you in a Project Server environment? What "flavor" of Project 2016 do you have (i.e. Standalone, Project Online, Project 365)?

    John

    Monday, July 24, 2017 6:12 PM
  • I am using project 365 updated to the last version. Version 1706 (Build 8229.2103)

    I usualy use it in french

    I just put it in english and tried again with the folowing code:

    Public Sub test()
        OrganizerMoveItem pjTables, ActiveProject.Name, "Global.mpt", "Table 1", False
    End Sub

    I got the folowing messages:

    This value is not valid in this situation

    Check the field to see if it requires text,a date, or a number, and that you typed the information correctly

    And after clicking ok the folowing message

    Runtime error 1101

    The argument value is not valid.

    


    JBParadis

    Monday, July 24, 2017 8:44 PM
  • JBPardis,

    Okay, that complicates things. A while back I worked with a Russian user who was trying to implement hyperlinks. The same code worked every time for me but not for him. It turned out in the end that he was trying to use "Gantt Chart" as one of the arguments but it wasn't working because he needed to use the Russian name for that view. Once he made that change, it worked fine.

    A similar issue could exist for you although I'm not sure why it would work for task elements of the Organizer but not resource elements. Here's something you might try, instead of using a Type constant (i.e. pjTables) and a Boolean for the Task argument (i.e. false), try using the numerical equivalents for those arguments as follows:

    OrganizerMoveItem Type:=1, FileName:="Project1", ToFileName:="Global.MPT", Name:="Table 1", Task:=0

    If you haven't already, record a macro of you moving the resource Table 1 to the Global. Then look at the code generated and compare that to the code you wrote directly.

    John

    Monday, July 24, 2017 9:11 PM
  • I have tried recording a macro and using the registered code and I got the same error.

    I the code without de vba constant and got the same error.

    I tried the code wit a task table with the parameter task set to 0 and it moved the task table 



    JBParadis

    Tuesday, July 25, 2017 1:05 PM
  • JBParadis,

    Are you telling me that you manually went through the steps to move a resource table from the active file to the Global while recording a macro and then when you ran the recorded macro, you got an error? Was it the same error? Did the table get moved via the manual operation?

    And when you run the following code, it moves a task table and not the resource table?

    Sub Macro7()
    ' Macro Macro7
    ' Macro Recorded 7/24/17 by John.
        OrganizerMoveItem Type:=1, FileName:="Project1", ToFileName:="Global.MPT", Name:="Table 1", Task:=0
    End Sub

    If the above is all true, then none of it makes any sense.

    John

    Tuesday, July 25, 2017 3:04 PM
  • I just redid everything here are the steps:

    1. Create a resource table called table 1 using the view menu and table and create a new table.

    2. Strat registering a macro

    3.


    JBParadis

    Tuesday, July 25, 2017 3:10 PM
  • It seems i click on submit to fast.

    I start again:

    1. Create a resource table called Table 1 using the view menu and table and create a new table

    2. Start registering a macro macro1 in my case

    3. Open manualy the organizer copy Resource table 1 from project3 to global

    4. check if it was copied OK

    5. Stop registering the macro

    6. Open manualy the organizer to delete table 1 from global

    7. execute macro 1

    I got the same error as usual.

    Her is the code I got from registering the macro:

    Sub Macro1()
    ' Macro Macro1
    ' Macro enregistrée le 2017-07-25 par Jean Paradis.
        OrganizerMoveItem Type:=1, FileName:="Projet3", ToFileName:="Global.MPT", Name:="Table 1"
    End Sub

    notice that the macro did not use the task parameter

    I know it does not make sens that is why i am on this forum.

    I tried removing all the macros I had in global, i even deleted global from the directory where it should be and restarded Ms Project to get a clean start and a clean global.mpt file. I tried the code on another machine using windows 8 as OS and got the same error.

    Is it possible there is an option I should activate.

    I don't know what to try again.

    I could record what I do and send you the video but I am not shure I can include a video on the forum


    JBParadis

    Tuesday, July 25, 2017 3:22 PM
  • JBParadis,

    And. . . .

    John

    Tuesday, July 25, 2017 3:23 PM
  • JBParadis, 

    I'm here because I was searching to see if anyone else had the same problem.  I wanted to distribute my macros and autoload into Global.mpt. 

    I took the exact same approach but only only have 5 files so my names are hardcoded in quotes so there is no question about the correct name.

    I see exactly what you are seeing.  It gets hung up on the delete but not the first one.

    I also tried adding various sleeps between the operations and that seems to help some but not fix.  I added DoEvents with sleep but doesn't fix it.

    Using 2010 MS Project Professional.

    John doesn't seem to think this is really happening but I can confirm for sure.

    John, what is the recommended method for auto loading and distributing your macros for MS Project?  I don't want my customers to load into a template and into each Project file because then I can't do an update to all the Project files and each will have its own version of the macros.  Putting it into Global.MPT is the only thing that makes sense.

    Thanks, 

    Craig

    Sunday, September 10, 2017 5:23 PM
  • Craig,

    This thread is a bit dated so I've lost the handle. Two questions for you. First, what exactly is your issue? It would be helpful to see a simplified version of your macro code. Second, you indicate you are using Project 2010. Is that correct and if so, is it fully updated (i.e. version 14.0.7176.5000)?

    John

    Monday, September 11, 2017 2:10 AM