Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4
'///place these procedures on a standard module
Option Explicit
Public Const GWL_STYLE = -16
Public Const WS_CAPTION = &HC00000 Public Declare Function GetWindowLong _ Lib "user32" Alias "GetWindowLongA" ( _ ByVal hWnd As Long, _ ByVal nIndex As Long) As Long Public Declare Function SetWindowLong _ Lib "user32" Alias "SetWindowLongA" ( _ ByVal hWnd As Long, _ ByVal nIndex As Long, _ ByVal dwNewLong As Long) As Long Public Declare Function DrawMenuBar _ Lib "user32" ( _ ByVal hWnd As Long) As Long Public Declare Function FindWindowA _ Lib "user32" (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long '____________________________________________________________ Sub Form_Show() 'Hide Excel Application.Visible = False 'To close a form automatically Application.OnTime Now, "Form_Close" UserForm1.Show End Sub '____________________________________________________________ Sub Form_Close() 'To close a form automatically Dim datWaitTime As Date datWaitTime = TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 3) Application.Wait datWaitTime Unload UserForm1 Application.Visible = True End Sub '____________________________________________________________ Sub HideTitleBar(frm As Object) Dim lngWindow As Long Dim lFrmHdl As Long lFrmHdl = FindWindowA(vbNullString, frm.Caption) lngWindow = GetWindowLong(lFrmHdl, GWL_STYLE) lngWindow = lngWindow And (Not WS_CAPTION) Call SetWindowLong(lFrmHdl, GWL_STYLE, lngWindow) Call DrawMenuBar(lFrmHdl) End Sub '//Place these procedures on the UserForm1 module Option Explicit Private Sub UserForm_Initialize() HideTitleBar Me End Sub '____________________________________________________________ Private Sub UserForm_Click() 'Close this userform Unload Me End Sub
'PLACE IN A STANDARD MODULE
Option Explicit Option Private Module
Public Const GWL_STYLE = -16
Public Const WS_CAPTION = &HC00000 #If VBA7 Then Public Declare PtrSafe Function GetWindowLong _ Lib "user32" Alias "GetWindowLongA" ( _ ByVal hwnd As LongPtr, _ ByVal nIndex As Long) As Long Public Declare PtrSafe Function SetWindowLong _ Lib "user32" Alias "SetWindowLongA" ( _ ByVal hwnd As LongPtr, _ ByVal nIndex As Long, _ ByVal dwNewLong As Long) As Long Public Declare PtrSafe Function DrawMenuBar _ Lib "user32" ( _ ByVal hwnd As LongPtr) As Long Public Declare PtrSafe Function FindWindowA _ Lib "user32" (ByVal lpClassName As String, _ ByVal lpWindowName As String) As LongPtr #Else Public Declare Function GetWindowLong _ Lib "user32" Alias "GetWindowLongA" ( _ ByVal hWnd As Long, _ ByVal nIndex As Long) As Long Public Declare Function SetWindowLong _ Lib "user32" Alias "SetWindowLongA" ( _ ByVal hWnd As Long, _ ByVal nIndex As Long, _ ByVal dwNewLong As Long) As Long Public Declare Function DrawMenuBar _ Lib "user32" ( _ ByVal hWnd As Long) As Long Public Declare Function FindWindowA _ Lib "user32" (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long #End If Sub HideTitleBar(frm As Object) #If VBA7 Then Dim lFrmHdl As LongPtr #Else Dim lFrmHdl As Long #End If Dim lngWindow As Long lFrmHdl = FindWindowA(vbNullString, frm.Caption) lngWindow = GetWindowLong(lFrmHdl, GWL_STYLE) lngWindow = lngWindow And (Not WS_CAPTION) Call SetWindowLong(lFrmHdl, GWL_STYLE, lngWindow) Call DrawMenuBar(lFrmHdl) End Sub PLACE IN YOUR USERFORM Private Sub UserForm_Initialize() HideTitleBar Me End Sub 1. Private Sub ComboBox1_Change() 2. Dim ws As Worksheet 3. Dim Rng As Range 4. Dim Sel 5. Set ws = Sheets("Data") 6. Sel = Me.ComboBox1.Value 7. If Sel <> "" Then 8. Set Rng = ws.Columns(4).Find(Sel, lookat:=xlWhole) 9. If Not Rng Is Nothing Then 10. Me.TextBox1.Value = ws.Cells(Rng.Row, "A") 11. Me.TextBox2.Value = ws.Cells(Rng.Row, "B") 12. Me.TextBox3.Value = ws.Cells(Rng.Row, "C") 13. Else 14. Me.TextBox1.Value = "" 15. Me.TextBox2.Value = "" 16. Me.TextBox3.Value = "" 17. End If 18. End If 19. End Sub