如何使用Excel数据库VBA重命名多个PDF文件 [英] How to rename multiple pdf files used excel database vba
问题描述
在此先感谢您的帮助和评论.
Thanks in advance for your help and comments.
我遇到以下问题,但是我不知道是否有可能...我正在尝试重命名文件夹C中的PDF文件:\ ...我需要根据我拥有的工作表重命名在根据pdf文件排序的excel中.我想使用excel中的电子表格数据重命名吗?
I have the following problem, but I do not know if it is possible ... I am trying to rename PDF files that are in the folder C: \ ... I need to rename according to a worksheet that I have in excel that is ordered according to the pdf files .. I would like to rename with the spreadsheet data in excel?
我有一个研究过的代码,但是没有搜索数据库,但是它要求我输入每个文件的名称
I have a code that I researched but it does not search my database, but it asks me to enter the name of each file
公共Sub lsSelecionaArquivo() Dim Caminho As String 昏暗的NomeBase作为字符串
Public Sub lsSelecionaArquivo() Dim Caminho As String Dim NomeBase As String
Caminho = InputBox("Informe o local dos arquivos a serem renomeados:", "Pasta", "C:\TEMP")
NomeBase = InputBox("Informe o local dos arquivos a serem renomeados:", "Renomear", "")
lsRenomearArquivos Caminho, NomeBase
结束子
公共Sub lsRenomearArquivos(Caminho作为字符串,NomeBase作为字符串)
Public Sub lsRenomearArquivos(Caminho As String, NomeBase As String)
Dim FSO As Object, Pasta As Object, Arquivo As Object, Arquivos As Object
Dim Linha As Long
Dim lSeq As Long
Dim lNovoNome As String
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.FolderExists(Caminho) Then
MsgBox "A pasta '" & Caminho & "' não existe.", vbCritical, "Erro"
Exit Sub
End If
lSeq = 1
Set Pasta = FSO.GetFolder(Caminho)
Set Arquivos = Pasta.Files
Cells(1, 1) = "De"
Cells(1, 2) = "Para"
Linha = 2
For Each Arquivo In Arquivos
Cells(Linha, 1) = UCase$(Arquivo.Path)
lNovoNome = Caminho & "\" & NomeBase & lSeq & Right(Arquivo, 4)
Name Arquivo.Path As lNovoNome
Cells(Linha, 2) = lNovoNome
lSeq = lSeq + 1
Linha = Linha + 1
Next
结束子
推荐答案
感谢帮助
自从我学习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
这篇关于如何使用Excel数据库VBA重命名多个PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!