I’m trying to export to pdf all the sheets of a workbook, where each sheet is given a name based on its content using this code:
Dim Ruta As String
Dim NombreArchivo As String
Dim hoja As Object
For Each hoja In ThisWorkbook.Sheets
NombreArchivo = "REG_PPR.004_003_" & hoja.Range("Q7") & "_" & hoja.Range("P8")
hoja.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=Ruta & "" & NombreArchivo & ".pdf", OpenAfterPublish:=False
Next hoja
Thing is, multiple sheets will have similar content and therefore the same name, which results in overwriting.
I thought about checking for a file with the same name before exporting and adding a “(1)” at the end, and fuse the pdf’s later with Acrobat, but maybe there’s a way to check for sheets that will have the same pdf name or sheets that have similar actual sheet name, for example Sheet, Sheet (1), Sheet (2), etc.
I hope I made sense, english is not my mother tonge as you can see by the variable names.
Antón Brea Sendón is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.