How can I password protect an Excel UserForm but allow it to be reopened without the password?
Tag : excel , By : user121501
Date : March 29 2020, 07:55 AM
around this issue To password protect this panel, you just need to add some code that checks to see if the user entered the correct password. This is pretty simple using an InputBox and a conditional. Sub macShowDevPanel()
' Source: http://www.excel-easy.com/vba/examples/protect-macro.html
Dim password as String
Select Case password
Case Is = False
' do nothing
Case Is = "CTM"
frmDevPanel.Show
Case Else
MsgBox ("Incorrect Password")
End Select
End Sub
Public password as String
Sub macShowDevPanel()
If password <> "CTM" Then
password = Application.InputBox("Enter the Dev Panel password", "Dev Panel - Password Protected")
End If
Select Case password
Case Is = "CTM"
frmDevPanel.Show
Case Else
MsgBox ("Incorrect Password")
End Select
End Sub
|
How to make my UserForm code change the output cell of the code every time I run said UserForm in Excel
Tag : excel , By : new Blackberry devel
Date : March 29 2020, 07:55 AM
seems to work fine I must have misunderstood your question. Instead of the "last used row" you need to find the last row in column "C" that has a shape in it. This changed code will find the last row with a shape in column C, then it will add 2 rows to that number, and then place the image two rows beneath the lowest one. You can change those rows to however many you need. You might get an error if there are no shapes on the sheet when this is run. If so then you will have to create an error capture for that. Private Sub CommandButton4_Click()
Dim ws As Worksheet
Dim ImgPath As String
Dim W As Double, H As Double
Dim L As Long, T As Long
Dim myArr() As Variant, myArrCounter As Long
Dim newRowNumb As Long
Set ws = ThisWorkbook.Sheets("Mobile POS Log Sheet")
'//////////////////////////////////////// This section will find the row of the bottom most shape in Column C
ReDim myArr(1 To 1)
myArrCounter = 0
For Each wshape In ws.Shapes
myArrCounter = myArrCounter + 1
If myArrCounter = 1 And wshape.TopLeftCell.Column = 3 Then
myArr(myArrCounter) = wshape.TopLeftCell.row
Else:
If wshape.TopLeftCell.Column = 3 And wshape.TopLeftCell.row > myArr(UBound(myArr)) Then
ReDim Preserve myArr(1 To myArrCounter)
myArr(myArrCounter) = wshape.TopLeftCell.row
End If
End If
Next wshape
newRowNumb = myArr(UBound(myArr)) + 2 ' this adds two rows to place the new picure. Change the "2" to how many rows you need
'~~> This is my current pic file path
ImgPath = "C:\Users\raphaelo\Downloads\test.gif"
With ws
W = 30 '<~~ Width
H = 11 '<~~ Height
L = .Range("c" & newRowNumb).Left '<~~ This is what should be changing each time I run the command
T = .Range("c" & newRowNumb).Top '<~~ This is what should be changing each time I run the command
'<~~ Both the L and T Range entries should change to the next cell (C3 to C4 to C5 and so on) One digit up every time I run the Command Code
'<~~ Unless it's the Placement entry below?
With .Pictures.Insert(ImgPath)
With .ShapeRange
.LockAspectRatio = msoTrue
.Width = W
.Height = H
End With
.Left = L
.Top = T
.Placement = 1 '<~~ Not sure if this is the one that should change one digit up each time I run the Command instead?
End With
End With
End Sub
|
Excel VBA - Remember SQL ODBC User/Password
Date : March 29 2020, 07:55 AM
I hope this helps . I managed to ask the password from the standard window with this code: ActiveWorkbook.Worksheets("Base").ListObjects(1).QueryTable.Refresh
|
Excel VBA Userform login with username and password on server
Tag : excel , By : user119413
Date : March 29 2020, 07:55 AM
it helps some times To help you with the obtaining the usernames and passwords part: You could use the text to columns functionality in Excel to split into two columns and then loop those. However, I would read the CSV column A info into an array and then loop the array. Use the Split function with delimiter ";" to generate your pairs, assign the values from the split to password and username variables and then use those for your testing. Option Explicit
Public Sub test()
Dim ws As Worksheet, loginDetails(), currentLogin As Long, pairs() As String, lastRow As Long
Set ws = Workbooks("name of CSV").Worksheets("Sheet1") '<==change this to the open CSV name
Dim pword As String, username As String
With ws
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
If lastRow = 1 Then '<change to 2 if header present
ReDim loginDetails(1, 1): loginDetails(1, 1) = .Range("A1").Value '<= change this to A2 if header
Else
loginDetails = .Range("A1:A" & .Cells(.Rows.Count, "A").End(xlUp).Row).Value 'Change to A2: if header present
End If
For currentLogin = LBound(loginDetails, 1) To UBound(loginDetails, 1)
pword = vbNullString: username = vbNullString
If InStr(loginDetails(currentLogin, 1), ";") > 0 Then
pairs = Split(loginDetails(currentLogin, 1), ";")
username = pairs(0)
pword = pairs(1)
'Debug.Print username, pword
'other code to test login
End If
Next
End With
End Sub
|
Input username and password for SQL Server from userform VBA Excel
Tag : sql , By : Sandeep Arneja
Date : October 02 2020, 05:00 PM
wish helps you I want to input username and password SQL Server from userform VBA Excel, but I don't understand how to do that. So I create code like this: , You need single quotes around the strings like this: cnn.ConnectionString = "Provider=SQLOLEDB;Data Source=172.20.20.20;Initial Catalog=bank;User ID='" & txtUser.Text & "';Password='" & txtPass.Text & "';"
|