乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 34|回复: 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-20111005-Schematic Design Issue55-20110526 PreliminaryLayoutsCommonDialog1.Filter="图形文件(*.dwg)|*。图纸|“
&nbsp CommonDialog1.DialogTitle="选择要打印的图形文件
&nbsp CommonDialog1.MaxFileSize=5000&nbsp CommonDialog1.FilterIndex=1&nbsp CommonDialog1.InitDir="F: \项目\“
&nbsp CommonDialog1.flags=(FileOpenConstants.cdlOFNAllowMultiselect)&nbsp CommonDialog1.ShowOpen&nbsp
 如果CommonDialog1.FileName&lt&燃气轮机&引用&引用;然后&nbsp&nbsp lsFiles=Split(CommonDialog1.FileName)&nbsp&nbsp&nbsp&nbsp 对于i=LBound(lsFiles)到UBound(lsFiles)&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp txtFile=UBound(lsFiles)
&nbsp&nbsp&nbsp&nbsp 下一步&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
&nbsp&nbsp&nbsp&nbsp 如果txtFile<2然后&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp MsgBox“;这是一个Batch Plot实用程序:请选择多个图形;,“vbInformation”;批处理实用程序“
&nbsp&nbsp&nbsp&nbsp 其他&nbsp&nbsp&nbsp&nbsp&nbsp
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp stmprefix=lsFiles(1)&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp STMPREFIX=Mid(STMPREFEX,1,InStr(1,STMPREfix,“-”)-1) &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 对于i=LBound(lsFiles)到UBound(lsFiles)&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp lstDwgList。添加项lsFiles(i)&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 下一步&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
&nbsp&nbsp&nbsp&nbsp 如果结束 如果有人能看一下上面的代码示例,看看他们是否能确定可能导致问题的原因,我们将不胜感激
提前感谢您的帮助
问候你,文斯
回复

使用道具 举报

0

主题

12

帖子

6

银币

初来乍到

Rank: 1

铜币
13
发表于 2012-2-7 15:43:53 | 显示全部楼层
这是我在VBA应用程序中使用的一个类模块。我不使用CommonDialog控件
我也不知道这是否适用于Windows 7或AutoCAD 2012
  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 11:08 , Processed in 0.527478 second(s), 56 queries .

© 2020-2025 乐筑天下

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