我正在为excel编写一个代码,它将包含一个包含文本框和按钮的表单。 按钮选择文件夹目录并将其写入文本框。 部分表格是这个!
它的代码就是这个
Private Sub CommandButton1_Click()
Dim diaFolder As FileDialog
On Error GoTo ErrorHandler
Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
diaFolder.AllowMultiSelect = False
diaFolder.Title = "Select a folder then hit OK"
diaFolder.Show
TextBox1.Text = diaFolder.SelectedItems(1)
Set diaFolder = Nothing
Exit Sub
ErrorHandler:
Msg = "No folder selected, you must select a folder for program to run"
Style = vbError
Title = "Need to Select Folder"
Response = MsgBox(Msg, Style, Title)
End Sub
问题是如何保存“文本框”值以在每次调用userform时显示它;它不应该依赖于工作簿中的单元格,因为它将是一个加载项,并将从功能区按钮调用。
非常感谢任何想法! 感谢。