Get spoken welcome massage Hi, In my work book i have set an interface sheet wit
ID: 3561589 • Letter: G
Question
Get spoken welcome massage
Hi,
In my work book i have set an interface sheet with userform login with authorization level
when the users fill its valid username, password and choose its level a popup form appear contain "Access Granted, Welcome"
how can i add the name of logged user after "Welcome". eg if Ahmed login the massage will be "Access Granted, Welcome Ahmed"
can I get this massage spoken, hope if this is available
the code of the userform
Private Sub ComboBox1_Change()
End Sub
Private Sub CommandButton2_Click()
Dim UserName As String, Password As String, Role As String
Dim ul As Worksheet, uc As Single, mUser As Range, p As Range
Dim ws As Worksheet, lr As Range
With Me
UserName = .TextBox1.Value
Password = .TextBox2.Value
Role = .ComboBox1.Value
If Not UserName <> "" Then
MsgBox "username missing"
.TextBox1.SetFocus
Exit Sub
End If
If Not Password <> "" Then
MsgBox "password missing"
.TextBox2.SetFocus
Exit Sub
End If
End With
Select Case Role
Case "User"
uc = 1
Case "Admin"
uc = 4
Case "Creator"
uc = 7
Case Else
MsgBox "Pls select a Role", vbCritical
Me.ComboBox1.SetFocus
Exit Sub
End Select
Set ul = Sheets("Login")
Set mUser = ul.Columns(uc).Find(UserName)
If mUser Is Nothing Then
MsgBox "Pls input a valid username or check your role"
Exit Sub
Else
End If
Set p = mUser.Offset(, 1)
If Password <> p.Value Then
MsgBox "Invalid password"
Me.TextBox2.SetFocus
Exit Sub
End If
Unload Me
Application.ScreenUpdating = False
Select Case uc
Case Is = 1
Sheets("Monthly").visible = -1
Application.DisplayFormulaBar = False
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""RIBBON"", FALSE)"
Case Is = 4
Sheets("Monthly").visible = -1
Sheets("SysUse").visible = -1
Application.DisplayFormulaBar = False
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""RIBBON"", FALSE)"
Case Is = 7
For Each ws In ThisWorkbook.Sheets
ws.visible = xlSheetVisible
Next
End Select
With ul
Set lr = .Cells(.Rows.Count, 10).End(xlUp)(2)
lr.Value = UserName
lr.Offset(, 1).Value = Now
lr.Offset(, 2).Value = "Login"
End With
MsgBox "Access Granted, Welcome", vbInformation
Application.ScreenUpdating = True
End Sub
Private Sub UserForm_Initialize()
With Me.ComboBox1
.AddItem "User"
.AddItem "Admin"
.AddItem "Creator"
End With
End Sub
Explanation / Answer
The VBA speak method can only speak the contents of a cell, you can't pass a string to it and have it speak that string so this would fail:-
MyString = "Access granted, welcome " & Environ("Username")
MyString.Speak
So what we have to do is write the string we want spoken to a worksheet cell and have the code use that cell like in my last post like this
Range("A1") = "Access granted, welcome " & Environ("Username")
Range("A1").Speak
If you already have the values in the cells such as A1 to A3 you can use this
Range("A1:A3").Speak (xlByRows)
or for non-contiguous cells
Range("A1,B5,C8").Speak (xlByRows)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.