简体   繁体   English

Excel - 如何向单元格添加文件选择按钮?

[英]Excel - How to add a file selection button to a cell?

I am creating a model that requires the user to enter into certain cells the addresses of required spreadsheets, folders etc that the model uses. 我正在创建一个模型,要求用户在某些单元格中输入模型使用的所需电子表格,文件夹等的地址。

Rather than have the user cut and paste the addresses in, I was hoping to include some kind of form control in the cell itself that would prompt the user to browse for the file and then return the filepath to the cell once the user had selected 'ok'. 我没有让用户剪切和粘贴地址,而是希望在单元格中包含某种表单控件,提示用户浏览文件,然后在用户选择后将文件路径返回到单元格。好'。

Is there a standard Windows form control that will acheive this? 是否有一个标准的Windows窗体控件可以实现这一点? It feels like there should be but all I can find are toggle buttons, drop-down menus etc? 感觉应该有,但我能找到的只是切换按钮,下拉菜单等?

I know I can write a custom script to capture the double_click event, any pointers on a more 'native' way to do it would be much appreciated! 我知道我可以编写一个自定义脚本来捕获double_click事件,任何以更“原生”方式执行此操作的指针都将非常感激!

Thanks, 谢谢,

Adam 亚当

You can connect a form button to the file open dialog. 您可以将表单按钮连接到文件打开对话框。

This allows a user to select a file, but you do not have to open it. 这允许用户选择文件,但您不必打开它。

Sub GetFile()

Dim varFile As Variant

varFile = Application.GetOpenFilename("Excel files (*.xls), *.xls", , "Select a file", , False)
If varFile = False Then
    Exit Sub
Else
    ActiveCell.Value2 = varFile
End If

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM