首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

VBA系列讲座之十-64位office版本API函数声明

大家好,我们继续VBA中64位API函数声明方案,在64版本OFFICE学习VBA时如果还沿用之前的代码会有一些bug,为此我推出了各套教程均是适合64位Office版本和32位Office版本的。为了满足大家的需求,我陆续把在一些API函数如何在64位系统中声明的方法介绍给大家。今日是第九部分。

Declare PtrSafe Function RevertToSelf Lib "advapi32.dll" Alias "RevertToSelf" () As Long

Declare PtrSafe Function AccessCheck Lib "advapi32.dll" Alias "AccessCheck" (pSecurityDescriptor As SECURITY_DESCRIPTOR, ByVal ClientToken As LongPtr, ByVal DesiredAccess As Long, GenericMapping As GENERIC_MAPPING, PrivilegeSet As PRIVILEGE_SET, PrivilegeSetLength As Long, GrantedAccess As Long, ByVal Status As LongPtr) As Long

Type TOKEN_PRIVILEGES

PrivilegeCount As Long

Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES

End Type

Declare PtrSafe Function OpenProcessToken Lib "advapi32.dll" Alias "OpenProcessToken" (ByVal ProcessHandle As LongPtr, ByVal DesiredAccess As Long, TokenHandle As LongPtr) As Long

Declare PtrSafe Function OpenThreadToken Lib "advapi32.dll" Alias "OpenThreadToken" (ByVal ThreadHandle As LongPtr, ByVal DesiredAccess As Long, ByVal OpenAsSelf As Long, TokenHandle As LongPtr) As Long

Declare PtrSafe Function GetTokenInformation Lib "advapi32.dll" Alias "GetTokenInformation" (ByVal TokenHandle As LongPtr, TokenInformationClass As Integer, TokenInformation As Any, ByVal TokenInformationLength As Long, ReturnLength As Long) As Long

Declare PtrSafe Function SetTokenInformation Lib "advapi32.dll" Alias "SetTokenInformation" (ByVal TokenHandle As LongPtr, TokenInformationClass As Integer, TokenInformation As Any, ByVal TokenInformationLength As Long) As Long

Declare PtrSafe Function AdjustTokenPrivileges Lib "advapi32.dll" Alias "AdjustTokenPrivileges" (ByVal TokenHandle As LongPtr, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long

Declare PtrSafe Function AdjustTokenGroups Lib "advapi32.dll" Alias "AdjustTokenGroups" (ByVal TokenHandle As LongPtr, ByVal ResetToDefault As Long, NewState As TOKEN_GROUPS, ByVal BufferLength As Long, PreviousState As TOKEN_GROUPS, ReturnLength As Long) As Long

Declare PtrSafe Function PrivilegeCheck Lib "advapi32.dll" Alias "PrivilegeCheck" (ByVal ClientToken As LongPtr, RequiredPrivileges As PRIVILEGE_SET, ByVal pfResult As LongPtr) As Long

Declare PtrSafe Function AccessCheckAndAuditAlarm Lib "advapi32.dll" Alias "AccessCheckAndAuditAlarmA" (ByVal SubsystemName As String, HandleId As Any, ByVal ObjectTypeName As String, ByVal ObjectName As String, SecurityDescriptor As SECURITY_DESCRIPTOR, ByVal DesiredAccess As Long, GenericMapping As GENERIC_MAPPING, ByVal ObjectCreation As Long, GrantedAccess As Long, ByVal AccessStatus As LongPtr, ByVal pfGenerateOnClose As LongPtr) As Long

Declare PtrSafe Function ObjectOpenAuditAlarm Lib "kernel32" Alias "ObjectOpenAuditAlarmA" (ByVal SubsystemName As String, HandleId As Any, ByVal ObjectTypeName As String, ByVal ObjectName As String, pSecurityDescriptor As SECURITY_DESCRIPTOR, ByVal ClientToken As LongPtr, ByVal DesiredAccess As Long, ByVal GrantedAccess As Long, Privileges As PRIVILEGE_SET, ByVal ObjectCreation As Long, ByVal AccessGranted As Long, ByVal GenerateOnClose As LongPtr) As Long

Declare PtrSafe Function ObjectPrivilegeAuditAlarm Lib "advapi32.dll" Alias "ObjectPrivilegeAuditAlarmA" (ByVal SubsystemName As String, HandleId As Any, ByVal ClientToken As LongPtr, ByVal DesiredAccess As Long, Privileges As PRIVILEGE_SET, ByVal AccessGranted As Long) As Long

Declare PtrSafe Function ObjectCloseAuditAlarm Lib "advapi32.dll" Alias "ObjectCloseAuditAlarmA" (ByVal SubsystemName As String, HandleId As Any, ByVal GenerateOnClose As Long) As Long

Declare PtrSafe Function PrivilegedServiceAuditAlarm Lib "advapi32.dll" Alias "PrivilegedServiceAuditAlarmA" (ByVal SubsystemName As String, ByVal ServiceName As String, ByVal ClientToken As LongPtr, Privileges As PRIVILEGE_SET, ByVal AccessGranted As Long) As Long

Declare PtrSafe Function IsValidSid Lib "advapi32.dll" Alias "IsValidSid" (pSid As Any) As Long

Declare PtrSafe Function EqualSid Lib "advapi32.dll" Alias "EqualSid" (pSid1 As Any, pSid2 As Any) As Long

Declare PtrSafe Function EqualPrefixSid Lib "advapi32.dll" Alias "EqualPrefixSid" (pSid1 As Any, pSid2 As Any) As Long

Declare PtrSafe Function GetSidLengthRequired Lib "advapi32.dll" Alias "GetSidLengthRequired" (ByVal nSubAuthorityCount As Byte) As Long

Declare PtrSafe Function AllocateAndInitializeSid Lib "advapi32.dll" Alias "AllocateAndInitializeSid" (pIdentifierAuthority As SID_IDENTIFIER_AUTHORITY, ByVal nSubAuthorityCount As Byte, ByVal nSubAuthority0 As Long, ByVal nSubAuthority1 As Long, ByVal nSubAuthority2 As Long, ByVal nSubAuthority3 As Long, ByVal nSubAuthority4 As Long, ByVal nSubAuthority5 As Long, ByVal nSubAuthority6 As Long, ByVal nSubAuthority7 As Long, lpPSid As LongPtr) As Long

Declare PtrSafe Sub FreeSid Lib "advapi32.dll" Alias "FreeSid" (pSid As Any)

 积木编程的思路内涵:

在我的系列书籍中一直在强调“搭积木”的编程思路,这也是学习利用VBA的主要方法,特别是职场人员,更是要采用这种方案。其主要的内涵:

1 代码不要自己全部的录入。你要做的是把积木放在合适的位置然后去修正代码,一定要拷贝,从你的积木库中去拷贝,然后修正代码,把时间利用到高效的思考上。

2 建立自己的“积木库”。平时在学习过程中,把自己认为有用的代码放在一起,多积累,在用到的时候,可以随时拿来。你的积木库资料越多,你做程序的思路就会越广。

VBA的应用界定及学习教程:

VBA是利用Office实现个人小型办公自动化的有效手段(工具)。这是我对VBA的应用界定。在取代OFFICE新的办公软件没有到来之前,谁能在数据处理方面做到极致,谁就是王者。其中登峰至极的技能非VBA莫属!

我记得20年前自己初学VBA时,那时的资料甚少,只能看源码自己琢磨,真的很难。20年过去了,为了不让学习VBA的朋友重复我之前的经历,我根据自己多年VBA实际利用经验,推出了六部VBA专门教程,目前教程均通过32位和64位两种OFFICE系统测试。

第一套:VBA代码解决方案是VBA中各个知识点的讲解,教程共147讲,覆盖绝大多数的VBA知识点,提供的程序文件更是一座不可多得的代码宝库,是初学及中级人员必备教程;目前这套教程提供的版本是修订第二版,程序文件通过32位和64位两种OFFICE系统测试。

第二套:VBA数据库解决方案数据库是数据处理的专业利器,教程中详细介绍了利用ADO连接ACCDB和EXCEL的方法和实例操作,适合中级人员的学习。目前这套教程提供的是修订第一版教程,程序文件通过32位和64位两种OFFICE系统测试。

第三套:VBA数组与字典解决方案   数组和字典是VBA的精华,字典是VBA代码水平提高的有效手段,值得深入的学习,是初级及中级人员代码精进的手段。目前这套教程提供的版本是修订第一版,程序文件通过32位和64位两种OFFICE系统测试。

第四套:VBA代码解决方案之视频是专门面向初学者的视频讲解,可以快速入门,更快的掌握这门技能。这套教程是第一套教程(修订一版)的视频讲解,听元音更易接受。这套教程还会额外提供通过32位和64位两种OFFICE系统测试的程序文件。

第五套:VBA中类的解读和利用这是一部高级教程,讲解类的虚无与肉身的度化,类的利用虽然较少,但仔细的学习可以促进自己VBA理论的提高。这套教程的领会主要是读者的领悟了,领悟一种佛学的哲理。目前这套教程提供的版本是修订第一版,程序文件通过32位和64位两种OFFICE系统测试。

第六套教程:《VBA信息获取与处理》,这是一部高级教程,涉及范围更广,实用性更强,面向中高级人员。教程共二十个专题,包括:跨应用程序信息获得、随机信息的利用、电子邮件的发送、VBA互联网数据抓取、VBA延时操作,剪切板应用、Split函数扩展、工作表信息与其他应用交互,FSO对象的利用、工作表及文件夹信息的获取、图形信息的获取以及定制工作表信息函数等等内容。程序文件通过32位和64位两种OFFICE系统测试。

上述教程的学习顺序:13265或者43265。提供的程序文件更是一座巨大的代码库,供读者使用,如需要可以WeChat: NZ9668

学习VBA是个过程,也需要经历一种枯燥的感觉

“众鸟高飞尽,孤云独去闲。相看两不厌,只有敬亭山”。学习的过程也是修心的过程,修一个平静的心。在代码的世界中,心平静了,心情好了,身体自然而然就好。心静则正,内心里没有那么多邪知邪见,也就没有那么多妄想。利人就是利己。我的教程助力给正在努力的朋友。

“水善利万物而不争”,绵绵密密,微则无声,巨则汹涌。学习亦如此,知道什么是自己所需要的,不要蜷缩在一小块自认为天堂的世界里,待到暮年时再去做自欺欺人的言论。要努力提高自己,用一颗充满生机的心灵,把握现在,这才是进取。越是有意义的事情,困难会越多。愿力决定始终,智慧决定成败。不管遇到什么,都是风景。看淡纷争,看轻得失。学习时微而无声,利用时则巨则汹涌。“路漫漫其修远兮,吾将上下而求索”

每一分收获都是成长的记录,正是这种执着,成就了秋日的收货。最后将两阙词送给致力于VBA学习的朋友,让大家感受一下学习过程的枯燥与执着:

其一

浮云掠过,暗语无声,

唯有清风,惊了梦中啼莺。

望星,疏移北斗,

奈将往事雁同行。

阡陌人,昏灯明暗,

忍顾长亭。

多少VBA人,

暗夜中,悄声寻梦,盼却天明。

怎无凭!

其二

望空

不见云头

几缕秋风,几片残阳

几处雁阵,几点灯火阑珊

几行代码

哪里是属性,哪里是方法

哪里又是事件

呵,呵

几根青丝不见额头

分享我多年工作实际经验的成果,随喜这些有用的东西,给确实需要利用VBA的同路人。回向学习利用VBA的历历往事,不胜感慨,谨以这些文字以纪念,

分享成果,随喜正能量

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20201023A0FPGM00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券