如何从组合框中的路径名显示文件名 [英] How to display the file name from the path name in combobox

查看:66
本文介绍了如何从组合框中的路径名显示文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一段代码,它将提取特定文件夹/目录中存在的所有子文件夹。这是代码。

I have written a code which will extract all the sub folders which is present inside a particular folder/Directory. Here is the code.

ComboBox10.List = Split(CreateObject("wscript.shell").exec("cmd /c Dir ""C:\Users\inkapb\AppData\Local\Temp\EPC AutoTool\Projects\*."" /b /s").stdout.readall, vbCrLf)

在上面的代码中,所有子文件夹路径都被填充,而不是子文件夹名称被填充。
谁能帮助我达到我的要求

Here in the above code all the sub folder path is getting populated instead of the subfolder name. Can any one help me to achieve my requirement

推荐答案

我有不同的建议可以满足您的要求。

I have a different piece of suggestion to serve your requirement.

Sub AddHighPlusOne()
Dim cb As ComboBox
Set cb = ActiveSheet.ComboBox1
Dim objFS As Object
Dim folders As Object
Set objFS = CreateObject("Scripting.FileSystemObject")
Set folders = objFS.GetFolder(Application.ActiveWorkbook.Path)
cb.Clear
For Each Folder In folders.SubFolders
  cb.AddItem (Folder.Name)
Next
End Sub

这篇关于如何从组合框中的路径名显示文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆