none
New msgbox after old one finish RRS feed

  • Question

  • Dear Group.

    ive got this great Code from. Marcelo de Moraes Nogueira

    and it Works just fine.

    but i need a Little exstra options in it when the 3 options are ok then the msgbox aint show up anymor that's ok

    but when it's ok then i wont it to goto to a macro call "save as Pdffile"

    Public Sub ValidateCells()
       
    Dim message As String
       
    Dim IsConditionNotOK_1 As Boolean
       
    Dim IsConditionNotOK_2 As Boolean
       
    Dim IsConditionNotOK_3 As Boolean
       
       
    'test Conditions
        IsConditionNotOK_1
    = Len(Range("F6").Value) > 0 Or Len(Range("F8").Value) > 0
        IsConditionNotOK_2
    = Range("P48").Value = "."
        IsConditionNotOK_3
    = Range("P49").Value = "."
       
       
    'if all Conditions are ok, exit sub and do not show any msgbox
       
    If IsConditionNotOK_1 = False And IsConditionNotOK_2 = False And IsConditionNotOK_3 = False Then Exit Sub
       
       
    'create message
       
    If IsConditionNotOK_1 Then message = "HUSK AT INDSÆTTE KAMPNR" & vbCrLf & vbCrLf
       
    If IsConditionNotOK_2 Then message = message & "TJEK OGSÅ HOLDKAPTAJNERNES NAVNE" & vbCrLf & vbCrLf
       
    If IsConditionNotOK_3 Then message = message & "HVIS DE IKKE ER DER SÅ DOBBELTKLIK UD FOR LICENSNR PÅ HOLDKAPTAJNERNE" & vbCrLf & vbCrLf
       
       
    'remove line breaks if there is an error in at least 1 Condition (vbCrLf and vbNewLine are actualy two characters long)
       
    If IsConditionNotOK_1 Or IsConditionNotOK_2 Or IsConditionNotOK_3 Then
            message
    = Left(message, Len(message) - 4)
       
    End If
       
       
    'show msgbox
        MsgBox message
    , vbOK + vbInformation, "HUSK KAMP NUMMER"

    'somehow i know my code should be here but cant figure it out because the function If false then exit msgbox

    end Sub

    hope for help

    Friday, November 21, 2014 11:13 PM

Answers

  • Public Sub ValidateCells()
       
     Dim message As String
     Dim IsLineOK_1 As Boolean
     Dim IsConditionNotOK_1 As Boolean
     Dim IsConditionNotOK_2 As Boolean
     Dim IsConditionNotOK_3 As Boolean
     Dim IsConditionok As Boolean
     'test Conditions
    IsLineOK_1 = Len(Range("F6").Value) > 0 'Or Len(Range("F8").Value) = 0
    IsConditionNotOK_1 = Len(Range("F6").Value) = "" 'Or Len(Range("F8").Value) > 0
    IsConditionNotOK_2 = Range("P48").Value = "."
    IsConditionNotOK_3 = Range("P49").Value = "."
        
     'if all Conditions are ok, exit sub and do not show any msgbox
    If IsConditionNotOK_1 = False And IsConditionNotOK_2 = False And IsConditionNotOK_3 = False Then exit sub 

    Change the end of this line to" If IsConditionNotOK_1 = False And IsConditionNotOK_2 = False And IsConditionNotOK_3 = False Then "Call any name of Macro you want to run if thoose conditions in this macro is ok"

        'create message
         If Not IsLineOK_1 Then message = "Message Message Message" & vbCrLf & vbCrLf

       ' If IsConditionNotOK_1 Then message = "Message Message Message" & vbCrLf & vbCrLf
        If IsConditionNotOK_2 Then message = message & "Message Message Message" & vbCrLf  & "Dobbelt Klik På Hans Licensnr" & vbCrLf & vbCrLf
       
        If IsConditionNotOK_3 Then message = message & "Message Message Message" & vbCrLf & "Messag Message Message" & vbCrLf & vbCrLf
       
        'remove line breaks if there is an error in at least 1 Condition (vbCrLf and vbNewLine are actualy two characters long)
        If IsConditionNotOK_1 Or IsConditionNotOK_2 Or IsConditionNotOK_3 Then
           message = Left(message, Len(message) - 4)
      
        'show msgbox
        MsgBox message, vbOK + vbInformation, "Message Message"
       
       
    End If

    End Sub

    Wednesday, November 26, 2014 3:11 PM

All replies

  • I only speak and read and write English and not certain that I understand your question properly but I am guessing that you want to be able to get the users answer to the MsgBox and depending on the answer, decide what to do next. Is this correct? If so then the Users answer needs to be saved in a variable and then test the variable. Need to use buttons vbOKCancel so that the user has a choice.

    Note that in the MsgBox I like to use the argument names with the colon and equals because it makes the code self explanatory.

    Dim Response As Variant
    Dim Message As String

    Message = "The prompt for the user to see. Click OK or Cancel."


    'Following line assigns the users answer to the variable called Response
    Response = MsgBox(Prompt:=Message, Buttons:=vbOKCancel + vbInformation, Title:="HUSK KAMP NUMMER")

    'Test the Users answer. (Will be either vbOK or Cancel)
    If Response = vbOK Then
        MsgBox "User clicked OK"
        'Code here in lieu of MsgBox to call required code if OK
       
    Else    'If not vbOK then must be Cancel

        MsgBox "User clicked Cancel"
        'Code here in lieu of MsgBox to do something else if cancelled
       
    End If


    Regards, OssieMac

    Saturday, November 22, 2014 1:57 AM
  • hm it seem's to be a great code BUT where to put it into the code That Work's too

    Henrik-1

    Saturday, November 22, 2014 4:21 PM
  • hm it seem's to be a great code BUT where to put it into the code That Work's too

    Henrik-1

    I thought you would know enough about programming to be able to do that. Because I can't interpret your messages in the code, I am not sure that what I have provided is what you need. Perhaps you can convert the messages to English so I can understand exactly what you are trying to do. 


    Regards, OssieMac

    Saturday, November 22, 2014 7:51 PM
  • I give it a try then

    the code i got from another user in her is looking trough 4 cell's

    cell F6 Or F8 or and P48 And P49

    If cell f6and f8 er bigger than 0 then message line 1

    if cell P48 is "." then message line 2

    if cell p49 is "." then message line 3

    if all cell's are ok THEN no message

    if any of those cell's fail then message tell Wich options not ok

    The Function i need After alle options are OK is go to another Macro call SaveFileAsPdf ()

    The i should learn more about vba code but until i have learn i hat to got to those WHO could be aple to help

    and i can see where i shoul PUT yours Vba code in that code there is good enough just that it aint show anything after selected options are ok

    Henrik-1

     

    Saturday, November 22, 2014 8:53 PM
  • Try the following and see if it does what you want. I am still not certain that I understand your problem correctly. The code performs the 3 tests and if any one of the conditions is NOT ok then creates the message.

    If all of the conditions are OK then it calls the sub SaveFileAsPdf and then exits the sub without displaying any message box.

    If one or more conditions are NOT ok then it displays the message box and asks the user if they want to save the file as is or Cancel. (You will need to edit the bolded text to your language for this part of the message. Ensure that you leave the double quotes at beginning and end of the text.). If the user clicks Cancel then it exits the sub without doing any more. If the user clicks OK then it calls the sub SaveFileAsPdf.

    Public Sub ValidateCells()
        Dim message As String
        Dim Response As Variant
        Dim IsConditionNotOK_1 As Boolean
        Dim IsConditionNotOK_2 As Boolean
        Dim IsConditionNotOK_3 As Boolean
       
        'test Conditions
        IsConditionNotOK_1 = Len(Range("F6").Value) > 0 Or Len(Range("F8").Value) > 0
        IsConditionNotOK_2 = Range("P48").Value = "."
        IsConditionNotOK_3 = Range("P49").Value = "."
       
        'If all Conditions are ok, save the file and exit sub and do not show any msgbox
        If IsConditionNotOK_1 = False And IsConditionNotOK_2 = False And IsConditionNotOK_3 = False Then
           Call SaveFileAsPdf
           Exit Sub
       
        Else
            'If at least one condition is True then create message string
            If IsConditionNotOK_1 Then message = "HUSK AT INDSÆTTE KAMPNR" & vbCrLf & vbCrLf
            If IsConditionNotOK_2 Then message = message & "TJEK OGSÅ HOLDKAPTAJNERNES NAVNE" & vbCrLf & vbCrLf
            If IsConditionNotOK_3 Then message = message & "HVIS DE IKKE ER DER SÅ DOBBELTKLIK UD FOR LICENSNR PÅ HOLDKAPTAJNERNE" & vbCrLf & vbCrLf
           
            'Add a line to the message to tell user to click OK if file to be saved or Cancel if not to be saved
            message = message & "Click OK to save the file as is or" & vbCrLf _
                      & "Click Cancel to exit and go back and fix errors."
           
            'Display the message and save the users answer to the Response variable
            Response = MsgBox(Prompt:=message, Buttons:=vbOKCancel + vbInformation, Title:="HUSK KAMP NUMMER")
           
            'Test the Users answer. (Will be either vbOK or Cancel)
            If Response = vbOK Then     'If user clicks OK then call SaveFileAsPdf
                Call SaveFileAsPdf
               
            Else
                Exit Sub    'If User clicks Cancel then exit sub
            End If
        End If

    End Sub


    Regards, OssieMac

    Saturday, November 22, 2014 10:57 PM
  • Dont use more time on it I figure it out by my self ,change some function in they old code and that came to Work

    Thanks for give a try Any way your code was make new Msgbox after the one i already have THAT was not what i want but don't use more time on it it Works now

    Your regards from Henrik-1 from Denmark

    Sunday, November 23, 2014 10:12 PM
  • Hi Henrik-1,

    Glad to here that the issue was fixed. Would you mind sharing the solution with us so it can benefit others who have the same issue?

    >>New msgbox after old one finish<<

    From the description, I also wanted share some option. If you want to show the new message when the old one is not showed and met some condition, we colud use if-else. Here is a sample for your reference:

    Sub ShowMessagebox()
    If True Then
        MsgBox "first message!"
    Else
        If True Then
            MsgBox "second message!"
        End If
    End If
    End Sub

    Links below is some useful links for learning VBA programming:
    Welcome to the Visual Basic for Applications language reference for Office 2013

    If you have developing issue with VBA, you can get more effective response from Visual Basic for Applications (VBA), and if you have any issues about Excel Object model, please feel free to reopen a new thread in this forum.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, November 26, 2014 1:43 AM
    Moderator
  • Public Sub ValidateCells()
       
     Dim message As String
     Dim IsLineOK_1 As Boolean
     Dim IsConditionNotOK_1 As Boolean
     Dim IsConditionNotOK_2 As Boolean
     Dim IsConditionNotOK_3 As Boolean
     Dim IsConditionok As Boolean
     'test Conditions
    IsLineOK_1 = Len(Range("F6").Value) > 0 'Or Len(Range("F8").Value) = 0
    IsConditionNotOK_1 = Len(Range("F6").Value) = "" 'Or Len(Range("F8").Value) > 0
    IsConditionNotOK_2 = Range("P48").Value = "."
    IsConditionNotOK_3 = Range("P49").Value = "."
        
     'if all Conditions are ok, exit sub and do not show any msgbox
    If IsConditionNotOK_1 = False And IsConditionNotOK_2 = False And IsConditionNotOK_3 = False Then exit sub 

    Change the end of this line to" If IsConditionNotOK_1 = False And IsConditionNotOK_2 = False And IsConditionNotOK_3 = False Then "Call any name of Macro you want to run if thoose conditions in this macro is ok"

        'create message
         If Not IsLineOK_1 Then message = "Message Message Message" & vbCrLf & vbCrLf

       ' If IsConditionNotOK_1 Then message = "Message Message Message" & vbCrLf & vbCrLf
        If IsConditionNotOK_2 Then message = message & "Message Message Message" & vbCrLf  & "Dobbelt Klik På Hans Licensnr" & vbCrLf & vbCrLf
       
        If IsConditionNotOK_3 Then message = message & "Message Message Message" & vbCrLf & "Messag Message Message" & vbCrLf & vbCrLf
       
        'remove line breaks if there is an error in at least 1 Condition (vbCrLf and vbNewLine are actualy two characters long)
        If IsConditionNotOK_1 Or IsConditionNotOK_2 Or IsConditionNotOK_3 Then
           message = Left(message, Len(message) - 4)
      
        'show msgbox
        MsgBox message, vbOK + vbInformation, "Message Message"
       
       
    End If

    End Sub

    Wednesday, November 26, 2014 3:11 PM