excel vba make word from bytes code example
Example 1: excel vba make word from bytes
Public Function MakeInteger%(LoByte As Byte, HiByte As Byte)
If HiByte And &H80 Then
MakeInteger = ((HiByte * &H100&) Or LoByte) Or &HFFFF0000
Else
MakeInteger = (HiByte * &H100) Or LoByte
End If
End Function
Example 2: excel vba get list of Excel files in a folder
'VBA function to return an array of file names from a folder:
Public Function GetFiles(sPath$, Optional sFilter$ = "*.*")
Dim p&, f$, s$: s = Space(1e6)
f = Dir(sPath & _
String(Abs(Right(sPath, 1) <> "\"), "\") & sFilter)
Do While Len(f)
Mid(s, p + 1, Len(f) + 1) = f & vbLf
p = p + Len(f) + 1
f = Dir
Loop
GetFiles = Split(Left(s, p - 1), vbLf)
End Function
'--------------------------------------------------------------------
ExcelFiles = GetFiles("C:\temp", "*.xls*")
MsgBox LBound(ExcelFiles) '<--displays: 0
Example 3: excel vba left word from Long Integer
'If n is a 4-byte Long Integer, the Low (Left) Word is:
If n And &H8000& Then
LoWord = n Or &HFFFF0000
Else
LoWord = n And &HFFFF&
End If
'If n is a 4-byte Long Integer, the High (Right) Word is:
HiWord = (n And &HFFFF0000) \ &H10000
Example 4: excel vba create an array from a range
v = [a1:b20]
'If v is dimensioned as a variant then he above creates a 2d array,
'20 rows high by 2 columns wide and those 40 array elements contain
'the values from the specified range.
'The square brackets are shorthand notation. Another way to code the
'same thing is:
v = Range("a1:b20")
'In both of the above examples, the Range object is returning its
'default... the Range.Value property. But keep in mind that the
'Range.Value2 property is about 20% quicker. So it could be more
'performant to code these two examples like so:
v = [a1:b20].Value2
v = Range("a1:b20").Value2