明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2326|回复: 3

commondialog类在VBA中该怎么用(谢谢)

[复制链接]
发表于 2005-5-28 15:16:00 | 显示全部楼层 |阅读模式
这是我从网上下载的一段代码“不需要打开文件可以把文件夹中的所有DWG插入到当前图形”,运行起来说 commondialog 没有定义,我该怎么解决,谢谢大家! Sub IntBlkByDirDwg()
On Error GoTo Err_Control
Dim BlkFile As Variant
Dim i As Integer
Dim InstPnt As Variant
Dim BlkRefObj As AcadBlockReference
Dim varCancel As Variant BlkFile = GetDir("选择要插入图形所在的目录:", "*.dwg") If IsArray(BlkFile) Then
ThisDrawing.Utility.Prompt vbCrLf & " 你选定了" & Str(UBound(BlkFile) + 1) & "个图形"
For i = 0 To UBound(BlkFile)

InstPnt = ThisDrawing.Utility.GetPoint(, vbCrLf & " 请选择图形 " & JustFileName(BlkFile(i)) & " 的插入点:")
Set BlkRefObj = ThisDrawing.ModelSpace.InsertBlock(InstPnt, _
BlkFile(i), 1#, 1#, 1#, 0#)
Next End If Exit_Here:
Exit Sub
Err_Control:
Select Case Err.Number
Case -2147352567
varCancel = ThisDrawing.GetVariable("LASTPROMPT")
If InStr(1, varCancel, "*Cancel*") <> 0 And InStr(1, varCancel, "*取消*") <> 0 Then
Err.Clear
Resume Exit_Here
Else
Err.Clear
Resume
End If
Case -2145320928
Err.Clear
Resume Exit_Here
Case Else
Resume Exit_Here
End Select End Sub '返回指定目录下指定名称所有文件的函数
Function GetFileListByPath(Path As String, FileName As String) As Variant Dim s As String
Dim sFiles() As String
Dim i As Integer
s = Dir(Path & FileName)
If s <> "" Then
ReDim sFiles(i) As String
sFiles(i) = Path & s
i = 1
s = Dir()
While s <> ""
ReDim Preserve sFiles(i) As String
sFiles(i) = Path & s
i = i + 1
s = Dir()
Wend
GetFileListByPath = sFiles
End If End Function '选定目录的函数,使用了commonDialog类
Public Function GetDir(DialogTitle As String, FileName As String) As Variant Dim dlg As CommonDialog 问题就出在这里 Dim Path As String
Dim FileList As Variant Set dlg = New CommonDialog
dlg.DialogTitle = DialogTitle
If dlg.Browse Then
Path = dlg.Path
If Path <> "" Then
Path = Left$(Path, InStr(Path, vbNullChar) - 1)
If Right$(Path, 1) <> "\" Then Path = Path & "\"
FileList = GetFileListByPath(Path, "*.dwg")
GetDir = FileList
End If
End If
End Function '由文件全路径名称返回文件的函数
Public Function JustFileName(FileName) As String
On Error Resume Next
Dim count As Integer
For count = Len(FileName) - 1 To 1 Step -1
If Mid(FileName, count, 1) = "\" Or Mid(FileName, count, 1) = "/" Then
JustFileName = Right(FileName, Len(FileName) - count)
Exit For
End If
Next
End Function
发表于 2005-5-28 21:19:00 | 显示全部楼层
程序怎么这么熟悉,好象是我写的。
呵呵,现在用CommonDialog已经过时了,用API吧,实用函数栏目下有
 楼主| 发表于 2005-5-29 10:41:00 | 显示全部楼层
谢谢版主,本来就是在网上弄的一段嘛。谢谢你!!!
发表于 2012-4-4 11:08:27 | 显示全部楼层
感谢,原来这样了啊。
是这个么?http://www.mjtd.com/Functions/ArticleShow.asp?ArticleID=300
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 18:46 , Processed in 0.163834 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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