Msgbox notification with paasword by vba macro

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Msgbox notification with paasword by vba macro

Post by zyxw1234 »

Hi,
I am looking for a macro that will do the things mentioned below
when i run the macro it should create a msg box stating "upload the file" & that msgbox can only be closed by paasword & paasword will be 1234
without paasword that msgbox shouldn't be closed or disappear
So plz have a look & help me in solving this problem
Thnx in Advance


https://www.excelforum.com/excel-progra ... ost5356703

https://excelfox.com/forum/showthread.p ... -vba-macro

User avatar
HansV
Administrator
Posts: 78233
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Msgbox notification with paasword by vba macro

Post by HansV »

As others have pointed out to you, it is not possible to do what you want using a MsgBox (or InputBox).
You need to create a userform with a text box and a command button.
User sintek on ExcelForum has already created a sample workbook for you.
Best wishes,
Hans

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Re: Msgbox notification with paasword by vba macro

Post by zyxw1234 »

Code: Select all

Sub STEP10()

    Dim result As Boolean
    ' loop until we've got a positive result or user aborts:
    Do While result = False
        result = check_files
    Loop

End Sub


Function check_files() As Boolean

    Dim file1 As String: file1 = "C:\Users\**I've been banned**\Desktop\ap.xls"
    Dim FileExists As Boolean
    Dim filenames As Variant
    
    filenames = Array(file1)
    
    For Each f In filenames
        FileExists = False
        On Error Resume Next
        FileExists = ((GetAttr(f) And vbDirectory) <> vbDirectory)
        
        If Err.Number = 53 Then
            msg = f & " doesn't exist. "
            On Error GoTo 0
            Exit For
        End If
        
        If Err.Number = 76 Then
            msg = "Directory to " & f & " doesn't exist. "
            On Error GoTo 0
            Exit For
        End If
        
        On Error GoTo 0
    
    Next f
    
    If FileExists Then
        check_files = True
    Else
        pw = Application.InputBox(msg & vbCrLf & vbCrLf & "Please enter the password to clear this error.", "Password", , , , , , 1)
        If pw = "1234" Then
            ' success! Do nothing
            check_files = True
        Else
            MsgBox ("Sorry, the password wasn't correct.")        ' comment this out with an apostrophe if it's not needed
            check_files = False
        End If
    End If
    
End Function

If file is not present then this macro does the same it creates a msgbox stating file is not present & that msgbox can only be closed by paasword & paasword will be 1234
without paasword that msgbox shouldn't be closed or disappear


In this situation i need a popup stating upoad the file & that msgbox can only be closed by paasword & paasword will be 1234
without paasword that msgbox shouldn't be closed or disappear




something like that


I hope HansV Sir u r getting my point, what i wanted to explain

User avatar
HansV
Administrator
Posts: 78233
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Msgbox notification with paasword by vba macro

Post by HansV »

You can display a MsgBox or InputBox repeatedly, for example:

Code: Select all

Sub Upload()
    Do
    Loop Until InputBox(Prompt:="Enter password", Title:="Upload the file") = "1234"
End Sub
But the InputBox will ALWAYS disappear when the user clicks one of the buttons OK or Cancel.
There is no way to prevent the InputBox from closing.
Best wishes,
Hans

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Re: Msgbox notification with paasword by vba macro

Post by zyxw1234 »

Awesome HansV Sir
Thnx for helping me in solving this problem
I am looking for this only
Problem Solved
Have a Great Day