Yussi Ariefiyono
Posts tagged vba
File in use Vb
Apr 20th
just found nice code in internet, and i use it in one of my project. works great!
it will return the last user that open the file
Function LastUser(strPath As String) As String
‘// Code by Helen from http://www.xtremevbtalk.com/index.php?s=
‘// This routine gets the Username of the File In Use
‘// Credit goes to Helen for code & Mike for the idea
‘// Amendment 25th June 2004
‘// : Name changes will show old setting
‘// : you need to get the Len of the Name store just before
‘// : the double Padded nullstrings
Dim text As String
Dim strFlag1 As String, strflag2 As String
Dim i As Integer, j As Integer
Dim hdlFile As Long
Dim lNameLen As Byte
strFlag1 = Chr(0) & Chr(0)
strflag2 = Chr(32) & Chr(32)
hdlFile = FreeFile
Open strPath For Binary As #hdlFile
text = Space(LOF(hdlFile))
Get 1, , text
Close #hdlFile
j = InStr(1, text, strflag2)
i = InStrRev(text, strFlag1, j) + Len(strFlag1)
lNameLen = Asc(Mid(text, i – 3, 1))
LastUser = Mid(text, i, lNameLen)
End Function
List of SendKeys
Feb 8th
| Key | Code |
|---|---|
| BACKSPACE | {BACKSPACE}, {BS}, or {BKSP} |
| BREAK | {BREAK} |
| CAPS LOCK | {CAPSLOCK} |
| DEL or DELETE | {DELETE} or {DEL} |
| DOWN ARROW | {DOWN} |
| END | {END} |
| ENTER | {ENTER}or ~ |
| ESC | {ESC} |
| HELP | {HELP} |
| HOME | {HOME} |
| INS or INSERT | {INSERT} or {INS} |
| LEFT ARROW | {LEFT} |
| NUM LOCK | {NUMLOCK} |
| PAGE DOWN | {PGDN} |
| PAGE UP | {PGUP} |
| PRINT SCREEN | {PRTSC} (reserved for future use) |
| RIGHT ARROW | {RIGHT} |
| SCROLL LOCK | {SCROLLLOCK} |
| TAB | {TAB} |
| UP ARROW | {UP} |
| F1 | {F1} |
| F2 | {F2} |
| F3 | {F3} |
| F4 | {F4} |
| F5 | {F5} |
| F6 | {F6} |
| F7 | {F7} |
| F8 | {F8} |
| F9 | {F9} |
| F10 | {F10} |
| F11 | {F11} |
| F12 | {F12} |
| F13 | {F13} |
| F14 | {F14} |
| F15 | {F15} |
| F16 | {F16} |
| Keypad add | {ADD} |
| Keypad subtract | {SUBTRACT} |
| Keypad multiply | {MULTIPLY} |
| Keypad divide | {DIVIDE} |
| Key | Code |
|---|---|
| SHIFT | + |
| CTRL | ^ |
| ALT | % |
Check if table is exist vba
Feb 8th
Problem:
Check if table is exist
Solution:
Option Compare Database
Public Function TableExists(strTable As String) As Boolean
Dim strName As String
On Error Resume Next
‘If table exists already then strName will be > “”
strName = CurrentDb.TableDefs(strTable).name
TableExists = Not (strName = “”)
End Function
Shell and AppActivate command vba
Feb 8th
Problem:
You want to open the file using send key, and active it as a window
Solution:
‘Define the task ID
Dim dTaskID As Integer
‘Open the file with your application
dTaskID = Shell(“applicationYouWantToOpenWith.EXE path+nameofthefile”)
‘Make it active window
AppActivate (dTaskID)