【问题标题】:rename files from old to new as listed in csv将文件从旧文件重命名为新文件,如 csv 中所列
【发布时间】:2016-03-17 19:17:56
【问题描述】:

我有一个包含两列的 excel/CSV 文件。第一列是文件名,第二列是我想要的名称。 Excel/CSV 文件和 PDF 在同一个文件夹中

我怎样才能用最少的编程来做到这一点。我不是程序员。

例子

Column 1      Column 2
old1           New 1
old2           New 2
odl3           New 3

如果这样更容易,我总是可以在 excel 中的名称前面附加文件路径

谢谢

【问题讨论】:

  • 在 vba 中你可以使用Name old1 as New 1。您需要完整路径和 For Loop 才能遍历行。
  • @ScottHoltzman - 你能扩展一下吗?我记得我从未见过Name [] as New []。编辑:啊,没关系。我实际上已经在我的宏中使用过它......只是忘记了它!我会看看这个 OP。

标签: excel file rename names


【解决方案1】:

您必须提供文件所在的路径以及带有扩展名的名称。然后你最终可以在 VBA 中做这样的事情。

Sub NameFiles()
Dim Path = "c:\temp\" 'keep the backslash at the end
dim a as range
dim x as long
x = 2
For each a in Range("a2:a4") 
OldName = a.value 'make sure your column contains name with file extension.
NewName = cells(x,2).value 'make sure your new column has extensions also
Name Path & OldName As Path & NewName
x = x + 1
next a
End Sub

【讨论】:

    猜你喜欢
    • 2020-12-31
    • 1970-01-01
    • 2021-12-03
    • 2021-01-06
    • 2016-04-11
    • 2011-07-04
    • 1970-01-01
    • 1970-01-01
    • 2011-03-19
    相关资源
    最近更新 更多