乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 38|回复: 1

“看不到对话框中的子文件夹”

[复制链接]

19

主题

35

帖子

5

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
111
发表于 2012-2-7 10:07:04 | 显示全部楼层 |阅读模式
各位沼泽会员好,
我的公司已经迁移到64位Windows 7工作站,我们正在运行AutoCAD 2012。当我尝试使用我的一些VBA程序时,它们在我的旧32位Windows XP电脑上运行得非常好.....允许我浏览项目图形文件夹以选择图形文件的对话框看不到某些图形子文件夹,也看不到它们的图形文件内容。我不知道为什么我会遇到这种困难....??
文件夹名称的示例如下:
5515-2011 10 05-原理图设计问题
5515-20110526初步布局
我用来调用对话框以在文件夹中选择图形的VBA代码字符串如下:
CommonDialog1。Filter = "绘图文件(*。dwg) |*。dwg|"
CommonDialog1。DialogTitle = "选择要打印的图形文件"
CommonDialog1。max filesize = 5000 common dialog 1。FilterIndex = 1。InitDir = " F:\ Projects \ "
common dialog 1 . flags =(file open constants . cdlofnallowmultiselect)
common dialog 1。show open

If common dialog 1。FileName  " " Then
ls files = Split(common dialog 1。FileName)
For I = LBound(ls files)To UBound(ls files)
txt file = UBound(ls files)
下一个i

如果txtFile
MsgBox“这是一个批处理打印实用程序:请选择多个图形”,vbInformation,“批处理实用程序”
Else

stmprefix = ls files(1)
stmprefix = Mid(stmprefix,1,InStr(1,stmprefix),--AddItem lsFiles(i)
接下来我

End If
End If
如果有人能看一下上面的代码示例,看看他们是否能找出可能导致该问题的原因,我们将不胜感激。
提前感谢您的帮助....!问候你,文斯

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

3

主题

33

帖子

1

银币

初来乍到

Rank: 1

铜币
45
发表于 2012-2-7 15:43:53 | 显示全部楼层
这是我在VBA应用程序中使用的一个类模块。我不使用CommonDialog控件
我也不知道这是否适用于Windows 7或AutoCAD 2012。
clsFileDialog
  1. Option Explicit
  2. '//The Win32 API Functions///
  3. Private Declare Function GetSaveFileName Lib _
  4. "comdlg32.dll" Alias "GetSaveFileNameA" _
  5. (pOpenfilename As OPENFILENAME) As Long
  6. Private Declare Function GetOpenFileName Lib _
  7. "comdlg32.dll" Alias "GetOpenFileNameA" _
  8. (pOpenfilename As OPENFILENAME) As Long
  9. Private Declare Function FindWindow Lib "user32" _
  10. Alias "FindWindowA" (ByVal lpClassName As String, _
  11. ByVal lpWindowName As String) As Long
  12. '//A few of the available Flags///
  13. Private Const OFN_FILEMUSTEXIST = &H1000
  14. Private Const OFN_HIDEREADONLY = &H4
  15. Private Const OFN_ALLOWMULTISELECT = &H200
  16. 'This one keeps your dialog from turning into
  17. 'A browse by folder dialog if multiselect is true!
  18. 'Not sure what I mean? Remove it from the flags
  19. 'In the "Show Open" & "Show Save" methods.
  20. Private Const OFN_EXPLORER As Long = &H80000
  21. '//The Structure
  22. Private Type OPENFILENAME
  23.      lStructSize As Long
  24.      hwndOwner As Long
  25.      hInstance As Long
  26.      lpstrFilter As String
  27.      lpstrCustomFilter As String
  28.      nMaxCustFilter As Long
  29.      nFilterIndex As Long
  30.      lpstrFile As String
  31.      nMaxFile As Long
  32.      lpstrFileTitle As String
  33.      nMaxFileTitle As Long
  34.      lpstrInitialDir As String
  35.      lpstrTitle As String
  36.      flags As Long
  37.      nFileOffset As Integer
  38.      nFileExtension As Integer
  39.      lpstrDefExt As String
  40.      lCustData As Long
  41.      lpfnHook As Long
  42.      lpTemplateName As String
  43. End Type
  44. Private lngHwnd As Long
  45. Private strFilter As String
  46. Private strTitle As String
  47. Private strDir As String
  48. Private blnHideReadOnly As Boolean
  49. Private blnAllowMulti As Boolean
  50. Private blnMustExist As Boolean
  51. Public Property Let OwnerHwnd(WindowHandle As Long)
  52.     '//FOR YOU TODO//
  53.     'Use the API to validate this handle
  54.     lngHwnd = WindowHandle
  55.     'This value is set at startup to the handle of the
  56.     'AutoCAD Application window, if you want the owner
  57.     'to be a user form you will need to obtain its
  58.     'Handle by using the "FindUserForm" function in
  59.     'This class.
  60. End Property
  61. Public Property Get OwnerHwnd() As Long
  62.     OwnerHwnd = lngHwnd
  63. End Property
  64. Public Property Let Title(Caption As String)
  65.     'don't allow null strings
  66.     If Not Caption = vbNullString Then
  67.         strTitle = Caption
  68.     End If
  69. End Property
  70. Public Property Get Title() As String
  71.     Title = strTitle
  72. End Property
  73. Public Property Let Filter(ByVal FilterString As String)
  74.     'Filters change the type of files that are
  75.     'displayed in the dialog. I have designed this
  76.     'validation to use the same filter format the
  77.     'Common dialog OCX uses:
  78.     '"All Files (*.*)|*.*"
  79.     Dim intPos As Integer
  80.     Do While InStr(FilterString, "|") > 0
  81.     intPos = InStr(FilterString, "|")
  82.     If intPos > 0 Then
  83.         FilterString = Left$(FilterString, intPos - 1) _
  84.         & Chr$(0) & Right$(FilterString, _
  85.         Len(FilterString) - intPos)
  86.     End If
  87.     Loop
  88.     If Right$(FilterString, 2)  Chr$(0) & Chr$(0) Then
  89.         FilterString = FilterString & Chr$(0)
  90.     End If
  91.     strFilter = FilterString
  92. End Property
  93. Public Property Get Filter() As String
  94.     'Here we reverse the process and return
  95.     'the Filter in the same format the it was
  96.     'entered
  97.     Dim intPos As Integer
  98.     Dim strTemp As String
  99.     strTemp = strFilter
  100.     Do While InStr(strTemp, Chr$(0)) > 0
  101.     intPos = InStr(strTemp, Chr$(0))
  102.     If intPos > 0 Then
  103.         strTemp = Left$(strTemp, intPos - 1) _
  104.         & "|" & Right$(strTemp, _
  105.         Len(strTemp) - intPos)
  106.     End If
  107.     Loop
  108.     If Right$(strTemp, 1) = "|" Then
  109.         strTemp = Left$(strTemp, Len(strTemp) - 1)
  110.     End If
  111.     Filter = strTemp
  112. End Property
  113. Public Property Let InitialDir(strFolder As String)
  114.     'Sets the directory the dialog displays when called
  115.     If Len(Dir(strFolder)) > 0 Then
  116.         strDir = strFolder
  117.         Else
  118.         Err.Raise 514, "FileDialog", "Invalid Initial Directory"
  119.     End If
  120. End Property
  121. Public Property Let HideReadOnly(blnVal As Boolean)
  122.     blnHideReadOnly = blnVal
  123. End Property
  124. Public Property Let MultiSelect(blnVal As Boolean)
  125.     'allow users to select more than one file using
  126.     'The Shift or CTRL keys during selection
  127.     blnAllowMulti = blnVal
  128. End Property
  129. Public Property Let FileMustExist(blnVal As Boolean)
  130.     blnMustExist = blnVal
  131. End Property
  132. '@~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@
  133. ' Display and use the File open dialog
  134. '@~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@
  135. Public Function ShowOpen() As String
  136.     Dim strTemp As String
  137.     Dim udtStruct As OPENFILENAME
  138.     udtStruct.lStructSize = Len(udtStruct)
  139.     'Use our private variable
  140.     udtStruct.hwndOwner = lngHwnd
  141.     'Use our private variable
  142.     udtStruct.lpstrFilter = strFilter
  143.     udtStruct.lpstrFile = Space$(254)
  144.     udtStruct.nMaxFile = 255
  145.     udtStruct.lpstrFileTitle = Space$(254)
  146.     udtStruct.nMaxFileTitle = 255
  147.     'Use our private variable
  148.     udtStruct.lpstrInitialDir = strDir
  149.     'Use our private variable
  150.     udtStruct.lpstrTitle = strTitle
  151.     'Ok, here we test our booleans to
  152.     'set the flag
  153.     If blnHideReadOnly And blnAllowMulti And blnMustExist Then
  154.         udtStruct.flags = OFN_HIDEREADONLY Or _
  155.         OFN_ALLOWMULTISELECT Or OFN_EXPLORER Or OFN_FILEMUSTEXIST
  156.         ElseIf blnHideReadOnly And blnAllowMulti Then
  157.         udtStruct.flags = OFN_ALLOWMULTISELECT _
  158.         Or OFN_EXPLORER Or OFN_HIDEREADONLY
  159.         ElseIf blnHideReadOnly And blnMustExist Then
  160.         udtStruct.flags = OFN_HIDEREADONLY Or OFN_FILEMUSTEXIST
  161.         ElseIf blnAllowMulti And blnMustExist Then
  162.         udtStruct.flags = OFN_ALLOWMULTISELECT Or _
  163.         OFN_EXPLORER Or OFN_FILEMUSTEXIST
  164.         ElseIf blnHideReadOnly Then
  165.         udtStruct.flags = OFN_HIDEREADONLY
  166.         ElseIf blnAllowMulti Then
  167.         udtStruct.flags = OFN_ALLOWMULTISELECT _
  168.         Or OFN_EXPLORER
  169.         ElseIf blnMustExist Then
  170.         udtStruct.flags = OFN_FILEMUSTEXIST
  171.     End If
  172.     If GetOpenFileName(udtStruct) Then
  173.         strTemp = (Trim(udtStruct.lpstrFile))
  174.         ShowOpen = Mid(strTemp, 1, Len(strTemp) - 1)
  175.     End If
  176. End Function
  177. '@~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@
  178. ' Display and use the File Save dialog
  179. '@~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@
  180. Public Function ShowSave() As String
  181.     Dim strTemp As String
  182.     Dim udtStruct As OPENFILENAME
  183.     udtStruct.lStructSize = Len(udtStruct)
  184.     'Use our private variable
  185.     udtStruct.hwndOwner = lngHwnd
  186.     'Use our private variable
  187.     udtStruct.lpstrFilter = strFilter
  188.     udtStruct.lpstrFile = Space$(254)
  189.     udtStruct.nMaxFile = 255
  190.     udtStruct.lpstrFileTitle = Space$(254)
  191.     udtStruct.nMaxFileTitle = 255
  192.     'Use our private variable
  193.     udtStruct.lpstrInitialDir = strDir
  194.     'Use our private variable
  195.     udtStruct.lpstrTitle = strTitle
  196.     If blnMustExist Then
  197.         udtStruct.flags = OFN_FILEMUSTEXIST
  198.     End If
  199.     If GetSaveFileName(udtStruct) Then
  200.         strTemp = (Trim(udtStruct.lpstrFile))
  201.         ShowSave = Mid(strTemp, 1, Len(strTemp) - 1)
  202.     End If
  203. End Function

在代码中添加:
  1. Dim fd1 As New clsFileDialog
  2. SetFiles = False
  3. Set fd1 = New clsFileDialog
  4. fd1.FileMustExist = True
  5. fd1.OwnerHwnd = application.HWND
  6. fd1.Filter = "Drawings Files (*.dwg) |*.dwg"
  7. fd1.Title = "Select Drawings to Plot"
  8. fd1.MultiSelect = True
  9. fd1.InitialDir = "F:\Projects"
  10. strCTRFile = fd1.ShowOpen
  11. 'Then check for no selection and split like you are
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-6-30 10:53 , Processed in 1.179713 second(s), 67 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表