在64位cad中用VBA使用通用对话框(CommonDialog)的方法
大家知道,在64位cad中用VBA使用系统自带通用对话框(CommonDialog)控件是用不了的,因为这个控件是32位的,64位cad不能使用32位的控件和dll,本人采用activex exe方法,实现了在64位的环境中用VBA对通用对话框进行调用!首先下载我编写的这个activex exe:,解压,放在任意一个你愿意的文件夹下,
然后,在中打开vba编辑器,把下面的代码复制进编辑器:
Private Sub ss1()
Dim x As New ZZYCommonDialog
Dim bC As Boolean, lFSC As Long, strF() As String, sLD As String
x.ShowOpen ThisDrawing.Application.HWND32, bC, lFSC, strF, sLD'ThisDrawing.Application.HWND32,如果出错,用0代替
Debug.Print bC
If Not bC Then
Debug.Print lFSC
Debug.Print strF(0)
Debug.Print sLD
End If
Set x = Nothing
End Sub
Private Sub ss2()
Dim x As New ZZYCommonDialog
Dim bC As Boolean, oC As OLE_COLOR
x.ShowColor ThisDrawing.Application.HWND32, bC, oC
Debug.Print bC
Debug.Print oC
Set x = Nothing
End Sub
Private Sub ss3()
Dim x As New ZZYCommonDialog
Dim Canceled As Boolean, SelectedFont As String, Bold As Boolean, Italic As Boolean, Size As Integer, Underline As Boolean, StrikeOut As Boolean, Color As Long, FaceName As String
x.ShowFont ThisDrawing.Application.HWND32, Canceled, SelectedFont, Bold, Italic, Size, Underline, StrikeOut, Color, FaceName
Debug.Print Canceled, SelectedFont, Bold, Italic, Size, Underline, StrikeOut, Color, FaceName
Set x = Nothing
End Sub
Private Sub ss4()
Dim x As New ZZYCommonDialog
Dim bC As Boolean, lFSC As Long, strF As String, sLD As String
x.ShowSave ThisDrawing.Application.HWND32, bC, lFSC, strF, sLD
Debug.Print bC
Debug.Print lFSC
Debug.Print strF
Debug.Print sLD
Set x = Nothing
End Sub
再然后,点击VBA编辑器的菜单,“”-》“引用”,
出来以下对话框,再点“浏览”,然后出现如下对话框 ,找到刚才你解压的附件的文件夹,选择那个文件“ZZYCommonDialogForVBAx64.exe”(扩展名是exe,不要害怕,是activex exe,Word,excel也是这样的程序)
点“打开”,点“确定”。
如果没有任何提示,恭喜你,你引用成功了,接下来,按F5运行哪几个测试代码就行了,
其中ss1是测试“打开”对话框的,ss2是测试“选择颜色”对话框的,其它自己试吧!
有人试用了,说不支持过滤文件扩展名,所以增加一下这个功能,出个升级版,同时,原版免币!------------------
2018-06-16更新一下,支持选择多个文件,
我试了,显示
运行时错误‘429’
Activex部件不能创建对象
好像是代码里 "ThisDrawing.Application.HWND32"的问题,如果改成"0"的话可以运行成功,但是打开的颜色窗口在左上角,无法操作,不知道楼主这个该怎么解决?
https://blog.csdn.net/hmm1208/article/details/25836837
看一下这篇文章,了解一下activex组件的注册。
原则上,放在任何文件夹下都可以,但需要注册到注册表里
来个gif演示
还在只有楼主活跃在vba版了 前几天才把这个问题搞定,VB在64位下,也无法添加这个部件,现在搞定了
搞定什么 了
可以是这个部件了 哇,这个厉害。我赶紧试试。
页:
[1]
2