none
Runtime Error 1101 RRS feed

  • Question

  • Hi All

    I have copied a macro that works fine and made changes to the fields used in the macro and the file locations.  Now it does not work.  When it gets to writing the first value back to the destination file I get an error "The Argument Value is not Valid".

    Any advice/guidance would be appreciated.  The code (in full) is below:

    Sub SSCL_FJS_Plan_Alignment_Check()
    
    Dim pjApp As MSProject.Application
    Dim FileToOpen
    Dim Proj As MSProject.Project
    Dim ts As tasks
    Dim t As Task
    Dim fd As FileDialog
    Dim uid As Integer
    Dim ws As String
    Dim sDate As Long
    Dim row As Integer
    Dim wsCount As Integer
    Set pjApp = MSProject.Application
    Set ts = ActiveProject.tasks
    If pjApp Is Nothing Then
        MsgBox "Project is not installed"
        End
    End If
    
    pjApp.Visible = True
    'AppActivate "Microsoft Project"
    
    Application.DisplayAlerts = False
    
    For Each t In ts
        row = t.ID
        If Not t Is Nothing Then
            If Not t.Summary Then
                tws = t.GetField(FieldNameToFieldConstant("Text6"))
                tuid = t.GetField(FieldNameToFieldConstant("Text14"))
                If tws <> "" Then
                    If tuid = "" Then
                        GoTo NextOne
                    End If
                    On Error GoTo ErrorHandler
                    FileOpenEx Name:="D:\CPP Build Template\CPP Build Plans\MoJ Plans\" & tws & ".mpp", ReadOnly:=False, FormatID:="MSProject.MPP"
                    Projects("SSCL_L3_MoJ_Txfm_Plan.mpp").tasks(row).Date1 = ActiveProject.tasks.UniqueID(tuid).Start
                    Projects("SSCL_L3_MoJ_Txfm_Plan.mpp").tasks(row).Date2 = ActiveProject.tasks.UniqueID(tuid).Finish
                    Projects("SSCL_L3_MoJ_Txfm_Plan.mpp").tasks(row).Text11 = ActiveProject.tasks.UniqueID(tuid).Duration
                    Projects("SSCL_L3_MoJ_Txfm_Plan.mpp").tasks(row).Number10 = ActiveProject.tasks.UniqueID(tuid).PercentComplete
                    FileClose pjDoNotSave
                End If
            End If
        End If
    NextOne:
    Next t
    GoTo Finish:
    ErrorHandler:
    MsgBox ("Either the plan " & tws & ".mpp" & " is not available or the UID (" & tuid & ") in the source plan has changed.  Please check and re-run this routine." _
        & "This routine will now exit and you will need to re-run it once you have corrected the missing details or placed a copy of the missing plan into the correct folder.")
    Exit Sub
    'pjApp.FileClose pjDoNotSave
    Finish:
    FilterApply Name:="All Tasks"
    
    'pjApp.Quit
    Set pjApp = Nothing
    Application.DisplayAlerts = True
    MsgBox ("Transformation Storyboard Updated.....")
    End Sub
    

    Kind regards

    Tony


    TKHussar

    Tuesday, May 24, 2016 10:21 AM

Answers

  • Hi John

    A good point well made.  I will bear this in mind in the future.

    Thanks again.

    Kind regards

    Tony


    TKHussar

    • Marked as answer by TKHussar Tuesday, June 19, 2018 10:47 AM
    Tuesday, May 31, 2016 7:07 AM

All replies

  • Tony,

    First I would add the Option Explicit statement. There are several variables that are not defined which means they default to type "variant", but it is always good practice to explicitly define variables.

    Second, the "If Not t is Nothing Then" statement is essentially useless because the "row = t.ID" statement is above it. If there are any blank lines, the procedure will generate a runtime error.

    Without attempting to run the code, you might take a look at the tuid variable. It is apparently a string value stored in Text14 of the active project but it needs to be a type "long" and I see nothing that converts it before the first attempt to write to the destination file.

    On a side note, I see Rod Gill provided an answer to your other post on copying specific rows to a new plan, but you provided no feedback to him. I think he would appreciate some. I know I would.

    John

    Friday, May 27, 2016 4:02 PM
  • Hi John

    Many thanks for your response.  I will try this when I am back at work after the bank holiday.

    Thanks again.

    Tony


    TKHussar

    Saturday, May 28, 2016 9:51 AM
  • Tony,

    You're welcome, let me know if that helped.

    On a side note, I feel a little forum training is necessary. Those of us who respond on these forums are all volunteers. We do not work for Microsoft nor do we receive any benefits from Microsoft for our participation. We give freely of our own time to help Project users. A thank you response is always appreciated. In addition, if one or more of our responses is at least helpful, a vote is greatly appreciated and if our response answered the question, marking our response as the answer will help other users who may have the same or a similar issue.

    John

    Saturday, May 28, 2016 4:48 PM
  • Hi John

    A good point well made.  I will bear this in mind in the future.

    Thanks again.

    Kind regards

    Tony


    TKHussar

    • Marked as answer by TKHussar Tuesday, June 19, 2018 10:47 AM
    Tuesday, May 31, 2016 7:07 AM