像点击文件夹“浏览”按钮后,弹出浏览对话框,浏览确定后返回原来的对话框并得到的路径值返回到TextBox.text且刷新。下面在问号一行为什么出错。请大虾指点Public bbbpath As mainwindow
Private Sub Dir1_Change()
VBakPath = Dir1.Path
? Set bbbpath.BakPath.Text = VBakPath
end sub
Private Sub Dir1_Change()
VBakPath = Dir1.Path
? Set bbbpath.BakPath.Text = VBakPath
end sub
Private Sub Dir1_Change()
VBakPath = Dir1.Path
bbbpath.BakPath.Text = VBakPath
end sub
去掉set。
去掉Set也不行,提示Object variable or With block variable not set
中的bbbpath是mainwindow窗体的,不在同本窗体内
'一个窗体即可
'一个按钮一个textbox
Private Sub Command1_Click()
Dim myShell As Object
Set myShell = CreateObject("Shell.Application")
Dim s As String
Dim mfolder As Object
'调用系统的浏览文件夹对话框
Set mfolder = myShell.BrowseForFolder(Me.hWnd, "请选择文件夹", 1)
If Not mfolder Is Nothing Then
s = mfolder.Self.Path
Text1.Text = s
End If
Set mfolder = Nothing
Set myShell = Nothing
End Sub
当然上述过程用api实现也可,用api实现的代码网上有很多,我就不写了:)
太感谢了!!!