none
VBA Word Controlling Return from Called Sub RRS feed

  • Question

  • HI folks, I am a newbie to VBA (not a proffesional coder at all).  I am trying to automate the processing of a series of tables.  Depending on a keyword found (or not found) in a string; I want to call a particulare Sub.  I can get the "If" statement to work OK to a point.  When the keyword is found, the sub is called and runs OK.  My problem is that when the controll comes back to the calling procedure, It comes back and continues checking the string.  What I want to do is have the code look, and if it finds any  one of about 6 keywords, call a particular Sub, if not call a default sub, and once it does any one of these cases; go to the next table (snippet of code below).  Thanks for looking

    'checks for keyword for table style decision
        If InStr(strBeforeText, "PROF") Then Call Table_Proccesor_Profile(myTable)
        If InStr(strBeforeText, "FLAT") Then Call Table_Processor_Flatness(myTable)
        Call Table_Processor_Default(myTable)


     Next i

     


    Scott
    • Moved by Mark Liu-lxfModerator Wednesday, February 8, 2012 2:49 AM VBA issue (From:Visual Basic General)
    Monday, February 6, 2012 8:26 PM

Answers

  • Hi Bernie, I'm afraid this didn't work out.  If the first condition was not met, then the goto skipped the next check.  I am trying to convert the check to a real boolean, I suspect the if then is not working right because the "in string" check is not boolean.  Thanks anyway for looking and trying.

    Scott

    • Marked as answer by RSLeedy Wednesday, February 22, 2012 12:36 AM
    Wednesday, February 8, 2012 2:58 PM
  • Sorry - Check it this way:

    If InStr(strBeforeText, "PROF") > 0 Then
        Call Table_Proccesor_Profile(myTable)
        GoTo Finished 'Skip all the other checks
    End If

    If InStr(strBeforeText, "FLAT") > 0 Then
         Call Table_Processor_Flatness(myTable)
         GoTo Finished 'Skip all the other checks
    End If

    Call Table_Processor_Default(myTable)   

    Finished:

    Next i


    HTH, Bernie

    Wednesday, February 8, 2012 8:59 PM

All replies

  • Hello RSLeedy,

    HI folks, I am a newbie to VBA (not a proffesional coder at all). I am trying to automate the processing of a series of tables. Depending on a keyword found (or not found) in a string; I want to call a particulare Sub. I can get the "If" statement to work OK to a point. When the keyword is found, the sub is called and runs OK. My problem is that when the controll comes back to the calling procedure, It comes back and continues checking the string. What I want to do is have the code look, and if it finds any one of about 6 keywords, call a particular Sub, if not call a default sub, and once it does any one of these cases; go to the next table (snippet of code below). Thanks for looking

    'checks for keyword for table style decision
    If InStr(strBeforeText, "PROF") Then Call Table_Proccesor_Profile(myTable)
    If InStr(strBeforeText, "FLAT") Then Call Table_Processor_Flatness(myTable)
    Call Table_Processor_Default(myTable)


    Next i

     


    Scott


    Welcome to Msdn Forums, for vba question , is avialible dedicated Forum ,see link below http://social.msdn.microsoft.com/forums/en/isvvba/threads

    Best Regards.


    Monday, February 6, 2012 8:37 PM
  • HI folks, I am a newbie to VBA (not a proffesional coder at all).  I am trying to automate the processing of a series of tables.  Depending on a keyword found (or not found) in a string; I want to call a particulare Sub.  I can get the "If" statement to work OK to a point.  When the keyword is found, the sub is called and runs OK.  My problem is that when the controll comes back to the calling procedure, It comes back and continues checking the string.  What I want to do is have the code look, and if it finds any  one of about 6 keywords, call a particular Sub, if not call a default sub, and once it does any one of these cases; go to the next table (snippet of code below).  Thanks for looking

    'checks for keyword for table style decision
        If InStr(strBeforeText, "PROF") Then Call Table_Proccesor_Profile(myTable)
        If InStr(strBeforeText, "FLAT") Then Call Table_Processor_Flatness(myTable)
        Call Table_Processor_Default(myTable)


     Next i


    Scott
    Monday, February 6, 2012 8:43 PM
  • For some odd reason, I could not get this to post with line breaks..... Sorry for my poor HTML Attempt!

    'checks for keyword for table style decision

    If InStr(strBeforeText, "PROF") Then

    Call Table_Proccesor_Profile(myTable)

    Goto Finished 'Skip all the other checks

    End If

    Default procedure called here

    Finished:

    Next i


    HTH, Bernie

    Monday, February 6, 2012 11:41 PM
  • Thanks Bernie, I'll give this a try

    Scott

    Tuesday, February 7, 2012 6:03 PM
  • Hi Bernie, I'm afraid this didn't work out.  If the first condition was not met, then the goto skipped the next check.  I am trying to convert the check to a real boolean, I suspect the if then is not working right because the "in string" check is not boolean.  Thanks anyway for looking and trying.

    Scott

    • Marked as answer by RSLeedy Wednesday, February 22, 2012 12:36 AM
    Wednesday, February 8, 2012 2:58 PM
  • Sorry - Check it this way:

    If InStr(strBeforeText, "PROF") > 0 Then
        Call Table_Proccesor_Profile(myTable)
        GoTo Finished 'Skip all the other checks
    End If

    If InStr(strBeforeText, "FLAT") > 0 Then
         Call Table_Processor_Flatness(myTable)
         GoTo Finished 'Skip all the other checks
    End If

    Call Table_Processor_Default(myTable)   

    Finished:

    Next i


    HTH, Bernie

    Wednesday, February 8, 2012 8:59 PM