Have a program that’s dynamically generating an Excel file and a csv. The excel file has VBA code that loads the csv data “on load” and I want to dynamically call that csv by having the csv file have the same filename, but just the different extension. So, based on my understanding this if the xls file was here:
C:\directory\filename.xls
This VBA code:
Function GetFullName() As String
GetFullName = ThisWorkbook.FullName
End Function
Would result in
GetFullName() = "C:\directory\filename.xls"
So, if that’s correct (source of code), how do I replace “.xls” with “.csv” and then insert that value into a file call. Or for example, to keep it simple, the file has VBA that prints a PDF using this code; which would require me to use the GetFullName, and change “.xls” to “.pdf”:
Sub PrintPDF()
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\directory\filename.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False _
End Sub
Hope the problem is clear, if there’s a better solution concept, I’m open to it. If you’ve got questions, just let me know.
Replace could be exactly what you want:
You can extend this by including the extension you want like so: