excel - 将路径更改为单元格值
问题描述
我在这个页面上找到了下面的代码,它工作正常。但我希望它根据我的单元格的值将其保存到一个文件夹中,在本例中为 C1
例如。根文件位于:C:\Users\john
根据我在 C1 中的值,我希望将它保存在另一个地方,到我在 C1 中C:\Users\john\games\new
放置的任何路径,这就是文件应该保存的位置。希望您能理解,并期待任何帮助或建议。
Sub MakeFolders()
Dim Rng As Range, rw As Range, c As Range
Dim p As String, v As String
Set Rng = Selection
'process each selected row
For Each rw In Rng.Rows
p = ActiveWorkbook.Path & "\" 'set initial root path for this row
'process each cell in this row
For Each c In rw.Cells
v = Trim(c.Value) 'what's in the cell?
If Len(v) > 0 Then
If Len(Dir(p & v, vbDirectory)) = 0 Then MkDir (p & v) 'create if not already there
p = p & v & "\" 'append to path (regardless of whether it needed to be created)
End If
Next c
Next rw
End Sub
解决方案
推荐阅读
- sql - 从多列中获取单行中的 SQL 查询结果
- docker - docker-compose 主机名和本地解析
- r - 从R中目录中的多个文件计算平均值的标准误差
- laravel - 当我部署到服务器时,Laravel 项目中的 vue 组件没有更新
- java - 为从 web 视图中单击的每个列表项打开一个新活动
- ruby-on-rails - 通过多个关联查找记录
- python - 合并具有相同值的字典列表的最简单方法是什么?
- krpano - krpano:自定义插件操作未知/已注册?
- agens-graph - 如何更改 AgensGraph 上的 VLABEL?
- linux - 如何使用 netcat 更改监听规则?