ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
楼主: xiaochaoniunai

[求助] 求大神处理一下,VBA代码,在64位系统上运行不了,提醒错误

[复制链接]

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-3-6 15:14 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
请问可以回答详细一点或者帮我改一下么,这段代码我是在网上找的,不知道如何修改。

TA的精华主题

TA的得分主题

发表于 2023-3-6 15:27 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
  1.     #If VBA7 And Win64 Then
  2.         Declare PtrSafe Sub...
  3.     #Else
  4.         Declare Sub...
  5.     #End If
复制代码

TA的精华主题

TA的得分主题

发表于 2023-3-6 16:16 | 显示全部楼层
xiaochaoniunai 发表于 2023-3-6 14:57
谢谢大神,是不是增加一个Declare PtrSafe Function进行就32或者64都能用了。


#If VBA7 Then
'Office 2013 及以上
    #If Win64 Then
    'x64 主机
       Private Declare PtrSafe Function apiCopyFile Lib "kernel32" Alias "CopyFileA" _
          (ByVal lpExistingFileName As String, _
           ByVal lpNewFileName As String, _
           ByVal bFailIfExists As LongPtr) As LongPtr
    #Else
    'x86 主机
       Private Declare PtrSafe Function apiCopyFile Lib "kernel32" Alias "CopyFileA" _
          (ByVal lpExistingFileName As String, _
           ByVal lpNewFileName As String, _
           ByVal bFailIfExists As Long) As Long
    #End If
#Else
'Office 2010 及以下
   Private Declare Function apiCopyFile Lib "kernel32" Alias "CopyFileA" _
      (ByVal lpExistingFileName As String, _
       ByVal lpNewFileName As String, _
       ByVal bFailIfExists As Long) As Long
#End If

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-3-6 16:32 | 显示全部楼层
tanglf188 发表于 2023-3-6 16:16
#If VBA7 Then
'Office 2013 及以上
    #If Win64 Then

非常感谢,您辛苦了。这段代码是放到最前面,还是替换掉那段fuction???

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-3-6 16:33 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

刚这样试了一下,好像不行,还是报错。

TA的精华主题

TA的得分主题

发表于 2023-3-6 17:10 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
xiaochaoniunai 发表于 2023-3-6 16:33
刚这样试了一下,好像不行,还是报错。

报什么错?

  1. #If VBA7 And Win64 Then
  2.     Private Declare PtrSafe Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
  3.     Private Declare PtrSafe Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  4.     Private Declare PtrSafe Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, ByVal lpOverlapped As Long) As Long
  5.     Private Declare PtrSafe Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  6.     Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  7.     Private Declare PtrSafe Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
  8. #Else
  9.     Private PtrSafe Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
  10.     Private PtrSafe Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  11.     Private PtrSafe Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, ByVal lpOverlapped As Long) As Long
  12.     Private PtrSafe Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  13.     Private PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  14.     Private PtrSafe Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
  15. #End If
复制代码

TA的精华主题

TA的得分主题

发表于 2023-3-6 19:37 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-3-7 20:40 | 显示全部楼层

非常感谢您,我再用这个代码试试。 可以帮我在TXT文档里面直接改过来吗?

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-3-7 21:06 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

非常感谢您,真的可以了。太感激了。
#Else
    Private PtrSafe Function GetVersionEx
把这个改成了Private Declare Function GetVersionEx  就可以了,在32位和64位上面都可以用。

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-3-7 21:07 | 显示全部楼层

非常感谢您,真的可以了。太感激了。
#Else
    Private PtrSafe Function GetVersionEx
把这个改成了Private Declare Function GetVersionEx  就可以了,在32位和64位上面都可以用。
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-18 16:51 , Processed in 0.029680 second(s), 6 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表