且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Excel数据库VBA重命名多个PDF文件

更新时间:2023-02-12 21:45:54

感谢帮助

自从我学习Java并开始进行VBA以来,更改语言有点紧张.

It is a bit tense to change language since I study Java and started doing VBA.

运行代码时,我看到电子表格必须具有旧文件名和新文件名才能插入数据,但是有没有办法仅获取新数据呢?而且我尝试搜索如何使它们成为PDF,而不必在工作表中放入文件扩展名.

When I ran the code, I saw that it is necessary for the spreadsheet to have the old file name and the new one to insert the data, but there is no way to get it to just get the new data? And I've tried searching on how to make them as PDF without having to put the file extension in the worksheet.

抱歉,我的问题...我与VBA的联系不多.

Sorry for the questions ... I do not have much contact with VBA.

非常感谢您对我的帮助.

I thank you very much for helping me.

Sub RenameFiles()

Dim xDir As String
Dim xFile As String
Dim xRow As Long
With Application.FileDialog(msoFileDialogFolderPicker)
    .AllowMultiSelect = False
If .Show = -1 Then
    xDir = .SelectedItems(1)
    xFile = Dir(xDir & Application.PathSeparator & "*")
    Do Until xFile = ""
        xRow = 0
        On Error Resume Next
        xRow = Application.Match(xFile, Range("A:A"), 0)
        If xRow > 0 Then
            Name xDir & Application.PathSeparator & xFile As _
            xDir & Application.PathSeparator & Cells(xRow, "B").Value
        End If
        xFile = Dir
    Loop
End If
End With
End Sub

Sub ListFiles()
Dim MyFolder As String
Dim MyFile As String
Dim j As Integer
MyFolder = "C:\Users\AnaWill\Desktop\Holerites Folha\Nova pasta"
MyFile = Dir(MyFolder & "\*.*")
a = 0
Do While MyFile <> ""
    a = a + 1
    Cells(a, 2).Value = MyFile
    MyFile = Dir
Loop
End Sub