首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用串联重命名FileNames

使用串联重命名FileNames
EN

Stack Overflow用户
提问于 2019-03-26 15:39:44
回答 1查看 113关注 0票数 0

我目前有一个excel电子表格,它的输出如下

代码语言:javascript
复制
Old_Name               PlayerID        PlayerName
20190324181982.MTS      1               Jake Smith
20190324181963.MTS      2               Greg Johnson
20190324181923.MTS      3               Jake De Maria

“旧名称”栏跟踪我上传到计算机的视频文件。我尝试使用VBA代码(见下文)来识别存储文件夹中的“旧名称”,并将其更改为playerid + playername。例如,1杰克·史密斯。

代码语言:javascript
复制
Sub autofilename()
    Dim dca As Workbook
    Dim checklist As Worksheet
    Dim oldfilepath As String
    Dim old_name As String
    Dim playerid As String
    Dim playername As String
    Dim lastrow As Integer

    Set dca = ActiveWorkbook
    Set checklist = dca.Sheets("Venezuela_list")
    lastrow = checklist.Cells(Rows.Count, "A").End(xlUp).Row
    oldfilepath = "C:\Users\nhwal\Docs\Practice"

    For a = 2 To lastrow
        old_name = checklist.Cells(a, 1).Value
        playerid = checklist.Cells(a, 2).Value
        playername = checklist.Cells(a, 3).Value

        On Error Resume Next
        Name old_name & old_name As old_name & playerid & playername & " MTS.url"
    Next a
End Sub

不幸的是,我尝试的代码没有更改我的文件的名称。有没有人知道如何调整我的代码让文件更改名称?提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2019-03-26 18:14:35

你不能尝试:

代码语言:javascript
复制
Option Explicit

Sub trst()

    Dim Row As Long, LastRow As Long
    Dim FileLocation As String

    With ThisWorkbook.Worksheets("Sheet1") '<- Change Workbook / Sheet names

        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        FileLocation = "C:\Users\nhwal\Docs\Practice\"

        For Row = 2 To LastRow
            Name FileLocation & .Range("A" & Row).Value As FileLocation & .Range("A" & Row).Value & " " & .Range("B" & Row).Value & " " & .Range("C" & Row).Value & " MTS.url"
        Next Row

    End With

End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55351968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档