跟我学VBA,我这里专注VBA, 授人以渔。我98年开始,从源码接触VBA已经20余年了,随着年龄的增长,越来越觉得有必要把这项技能传递给需要这项技术的职场人员。希望职场和数据打交道的朋友,都来学习VBA,利用VBA,起码可以提高自己的工作效率,可以有时间多陪陪父母,多陪陪家人,何乐而不为呢?我的教程一共九套,从入门开始一直讲到程序的分发,是学习利用VBA的实用教程。这份API资料是随高级教程赠送的.
这讲我们继续学习64位Office API声明语句第120讲,这些内容是MS的权威资料,看似枯燥,但对于想学习API函数的朋友是非常有用的。
【分享成果,随喜正能量】 会因为有情绪而烦闷,也因为没控制情绪而懊悔。莫道幽人一事无,闲中尽有静工夫。情绪就像水,宜疏不宜堵。学会控制情绪,不能把情绪看得过重,也不能一味遏制情绪的产生。倾听所有声音,尊重所有声音,但只成为自己!不被情绪支配,才是高级自由!。
当学员学习到高级阶段,如果引用API,这个资料可以直接查到64位写法。大多数情况下我们是将低版本的程序文件升级到高版本,这时您就不必为如下的错误提示所困扰了:
Declare PtrSafe Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" (ByVal hMenu As LongPtr, ByVal un As Long, ByVal b As Long, lpMenuItemInfo As MENUITEMINFO) As Long
Declare PtrSafe Function GetMenuItemRect Lib "user32" Alias "GetMenuItemRect" (ByVal hWnd As LongPtr, ByVal hMenu As LongPtr, ByVal uItem As Long, lprcItem As RECT) As Long
Type SCROLLINFO
cbSize As Long
fMask As Long
nMin As Long
nMax As Long
nPage As Long
nPos As Long
nTrackPos As Long
End Type
Declare PtrSafe Function GetScrollInfo Lib "user32" Alias "GetScrollInfo" (ByVal hWnd As LongPtr, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long
Declare PtrSafe Function GetSysColorBrush Lib "user32" Alias "GetSysColorBrush" (ByVal nIndex As Long) As LongPtr
Declare PtrSafe Function GetUserObjectInformation Lib "user32" Alias "GetUserObjectInformationA" (ByVal hObj As LongPtr, ByVal nIndex As Long, pvInfo As Any, ByVal nLength As Long, lpnLengthNeeded As Long) As Long
Declare PtrSafe Function GetWindowContextHelpId Lib "user32" Alias "GetWindowContextHelpId" (ByVal hWnd As LongPtr) As Long
Declare PtrSafe Function GetWindowRgn Lib "user32" Alias "GetWindowRgn" (ByVal hWnd As LongPtr, ByVal hRgn As LongPtr) As Long
Declare PtrSafe Function GrayString Lib "user32" Alias "GrayStringA" (ByVal hDC As LongPtr, ByVal hBrush As LongPtr, ByVal lpOutputFunc As LongPtr, ByVal lpData As LongPtr, ByVal nCount As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Declare PtrSafe Function InsertMenuItem Lib "user32" Alias "InsertMenuItemA" (ByVal hMenu As LongPtr, ByVal un As Long, ByVal bool As Long, ByRef lpcMenuItemInfo As MENUITEMINFO) As Long
Declare PtrSafe Function LoadCursorFromFile Lib "user32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As LongPtr
Declare PtrSafe Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As LongPtr, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As LongPtr
Declare PtrSafe Function LookupIconIdFromDirectoryEx Lib "user32" Alias "LookupIconIdFromDirectoryEx" (presbits As Byte, ByVal fIcon As Long, ByVal cxDesired As Long, ByVal cyDesired As Long, ByVal Flags As Long) As Long
Declare PtrSafe Function MapVirtualKeyEx Lib "user32" Alias "MapVirtualKeyExA" (ByVal uCode As Long, ByVal uMapType As Long, ByVal dwhkl As LongPtr) As Long
Type MSGBOXPARAMS
cbSize As Long
hwndOwner As LongPtr
hInstance As LongPtr
lpszText As String
lpszCaption As String
dwStyle As Long
lpszIcon As String
dwContextHelpId As LongPtr
lpfnMsgBoxCallback As LongPtr
dwLanguageId As Long
End Type
Declare PtrSafe Function MessageBoxIndirect Lib "user32" Alias "MessageBoxIndirectA" (lpMsgBoxParams As MSGBOXPARAMS) As Long
Declare PtrSafe Function OpenDesktop Lib "user32" Alias "OpenDesktopA" (ByVal lpszDesktop As String, ByVal dwFlags As Long, ByVal fInherit As Long, ByVal dwDesiredAccess As Long) As LongPtr
Declare PtrSafe Function OpenInputDesktop Lib "user32" Alias "OpenInputDesktop" (ByVal dwFlags As Long, ByVal fInherit As Long, ByVal dwDesiredAccess As Long) As LongPtr
Declare PtrSafe Function OpenWindowStation Lib "user32" Alias "OpenWindowStationA" (ByVal lpszWinSta As String, ByVal fInherit As Long, ByVal dwDesiredAccess As Long) As LongPtr
Declare PtrSafe Function PaintDesktop Lib "user32" Alias "PaintDesktop" (ByVal hdc As LongPtr) As Long
Type WNDCLASSEX
cbSize As Long
style As Long
lpfnWndProc As LongPtr
cbClsExtra As Long
cbWndExtra As Long
hInstance As LongPtr
hIcon As LongPtr
hCursor As LongPtr
hbrBackground As LongPtr
lpszMenuName As String
lpszClassName As String
hIconSm As LongPtr
End Type
Declare PtrSafe Function RegisterClassEx Lib "user32" Alias "RegisterClassExA" (pcWndClassEx As WNDCLASSEX) As Integer
Declare PtrSafe Function SetMenuContextHelpId Lib "user32" Alias "SetMenuContextHelpId" (ByVal hMenu As LongPtr, ByVal dw As Long) As Long
Declare PtrSafe Function SetMenuDefaultItem Lib "user32" Alias "SetMenuDefaultItem" (ByVal hMenu As LongPtr, ByVal uItem As Long, ByVal fByPos As Long) As Long
Declare PtrSafe Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" (ByVal hMenu As LongPtr, ByVal un As Long, ByVal bool As Long, lpcMenuItemInfo As MENUITEMINFO) As Long
Declare PtrSafe Function SetMessageExtraInfo Lib "user32" Alias "SetMessageExtraInfo" (ByVal lParam As LongPtr) As LongPtr
Declare PtrSafe Function SetMessageQueue Lib "user32" Alias "SetMessageQueue" (ByVal cMessagesMax As Long) As Long
Declare PtrSafe Function SetProcessWindowStation Lib "user32" Alias "SetProcessWindowStation" (ByVal hWinSta As LongPtr) As Long
Declare PtrSafe Function SetScrollInfo Lib "user32" Alias "SetScrollInfo" (ByVal hWnd As LongPtr, ByVal n As Long, lpcScrollInfo As SCROLLINFO, ByVal bool As Long) As Long
Declare PtrSafe Function SetSystemCursor Lib "user32" Alias "SetSystemCursor" (ByVal hcur As LongPtr, ByVal id As Long) As Long
Declare PtrSafe Function SetThreadDesktop Lib "user32" Alias "SetThreadDesktop" (ByVal hDesktop As LongPtr) As Long
Declare PtrSafe Function SetTimer Lib "user32" Alias "SetTimer" (ByVal hWnd As LongPtr, ByVal nIDEvent As LongPtr, ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As LongPtr
Declare PtrSafe Function SetUserObjectInformation Lib "user32" Alias "SetUserObjectInformationA" (ByVal hObj As LongPtr, ByVal nIndex As Long, pvInfo As Any, ByVal nLength As Long) As Long
Declare PtrSafe Function SetWindowContextHelpId Lib "user32" Alias "SetWindowContextHelpId" (ByVal hWnd As LongPtr, ByVal dw As Long) As Long
Declare PtrSafe Function SetWindowRgn Lib "user32" Alias "SetWindowRgn" (ByVal hWnd As LongPtr, ByVal hRgn As LongPtr, ByVal bRedraw As Long) As Long
Declare PtrSafe Function SetWindowsHook Lib "user32" Alias "SetWindowsHookA" (ByVal nFilterType As Long, ByVal pfnFilterProc As LongPtr) As LongPtr
Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As LongPtr, ByVal hmod As LongPtr, ByVal dwThreadId As Long) As LongPtr
Declare PtrSafe Function ShowWindowAsync Lib "user32" Alias "ShowWindowAsync" (ByVal hWnd As LongPtr, ByVal nCmdShow As Long) As Long
Declare PtrSafe Function SwitchDesktop Lib "user32" Alias "SwitchDesktop" (ByVal hDesktop As LongPtr) As Long
Declare PtrSafe Function TileWindows Lib "user32" Alias "TileWindows" (ByVal hwndParent As LongPtr, ByVal wHow As Long, lpRect As RECT, ByVal cKids As Long, lpKids As LongPtr) As Integer
Declare PtrSafe Function ToAsciiEx Lib "user32" Alias "ToAsciiEx" (ByVal uVirtKey As Long, ByVal uScanCode As Long, lpKeyState As Byte, lpChar As Integer, ByVal uFlags As Long, ByVal dwhkl As LongPtr) As Long
Type TPMPARAMS
cbSize As Long
rcExclude As RECT
End Type
我20多年的VBA实践经验,全部浓缩在下面的各个教程中: