明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1565|回复: 2

如何通过编程来选择文件存放路径?

[复制链接]
发表于 2005-3-27 13:16:00 | 显示全部楼层 |阅读模式
如何通过编程来选择文件存放路径?


         我想实现VBA编程实现VB6.0中目录列表控件dirlistbox控件的功能,可以实现对文件目录的选取,用户从而可以选择文件存放路径.不知VBA中有没有这种控件,如没有,有没有办法可以这种功能.请高手赐教!
发表于 2005-3-27 19:27:00 | 显示全部楼层

回复

Public Sub Test_BrowseForFolder()
Dim str As String '$
str = ReturnFolder()
MsgBox str
End Sub

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2005-3-28 07:14:00 | 显示全部楼层
本帖最后由 作者 于 2005-3-28 7:45:45 编辑

Joe Sutphin 写过下面这个用comdlg32.dll的SaveAs对话框替代 Option Explicit Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias _
"GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomerFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustdata As Long
lpfnHook As Long
lpTemplateName As String
End Type Public Function ShowSave(Filter As String, _
InitialDir As String, _
DialogTitle As String) As String
Dim OFName As OPENFILENAME
'Set the structure size
OFName.lStructSize = Len(OFName)
'set the owner window
OFName.hwndOwner = 0
'set the filter
OFName.lpstrFilter = Filter
'set the maximum number of chars
OFName.nMaxFile = 255
'create a buffer
OFName.lpstrFile = Space(254)
'create a buffer
OFName.lpstrFileTitle = Space$(254)
'set the maximum number of chars
OFName.nMaxFileTitle = 255
'set the initial directory
OFName.lpstrInitialDir = InitialDir
'set the dialog title
OFName.lpstrTitle = DialogTitle
'no extra flags
OFName.flags = 0
'Show 'SaveAs File' dialog
If GetSaveFileName(OFName) Then
ShowSave = Trim(OFName.lpstrFile)
Else
ShowSave = ""
End If
End Function Sub Test_SaveAs()
Dim Filter As String
Dim InitialDir As String
Dim DialogTitle As String
Dim FileSelected As String Filter = "Drawing Files (*.dwg)" + Chr$(0) + "*.dwg" + Chr$(0) + _
"All File(*.*)" + Chr$(0) & "*.*" + Chr$(0)
InitialDir = "C:\Program Files\AutoCAD 2004\Sample"
DialogTitle = "Save DWG as file" FileSelected = ShowSave(Filter, InitialDir, DialogTitle)
If FileSelected <> "" Then
MsgBox "You just selected a file: " & FileSelected
Else
MsgBox "You didn't select a file."
End If
End Sub

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

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

本版积分规则

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

GMT+8, 2024-11-27 21:07 , Processed in 0.174557 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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