In Excel, using VBA, how do I take the “path+filename+extension” and change the extension?

后端 未结 1 1741
轻奢々
轻奢々 2021-01-28 22:27

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

1条回答
  •  执念已碎
    2021-01-28 22:46

    Replace could be exactly what you want:

    Function GetFullNameCSV() As String
    
     GetFullNameCSV = Replace(ThisWorkbook.FullName, ".xls",".csv")  
    
    End Function
    

    You can extend this by including the extension you want like so:

    sFileName = GetNewExt("pdf")
    
    Function GetNewExt(Ext As String) As String
    
     GetNewExt = Replace(ThisWorkbook.FullName, ".xls","." & Ext)  
    
    End Function
    

    0 讨论(0)
提交回复
热议问题