Extract Filename (including dots) without extension

Sinem

Board Regular
Joined
Nov 8, 2015
Messages
63
Hello,

I canot extract the filename without ".xlsm" because of the dots in the name.

The filename is: "Test 01.01.2019"

Here are my tries:

Code:
  FileName = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 5) 

 FileName= Len(ThisWorkbook.Name, InStrRev(ThisWorkbook.Name, ".") - 1)

The Workbook is saved as pdf data with the name "Test 01.01" and if I delete the date then I can save it normally as xlsx
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
How about
Code:
fileName = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - InStrRev(ThisWorkbook.Name, ".") - 1)
 
Upvote 0
Hi Fluff thank you but unfortunately not. It has problems with the date format. If it's 01-01-2019 then it can handle it perfectly. But it doesnt like the dots anyhow.
 
Upvote 0
Hi Rick,

here is my a part of my code:

Code:
Public Sub fkt_Copy()

    Dim str_Path_Dest As String
    Dim str_FileName As String
    Dim str_DestPathName As String
    Dim fnPos As Integer
    Dim foFS As FileSystemObject
    
    
    Dim xApp As Excel.Application
    Dim xWbk As Workbook
    Dim ws As Worksheet
   
   
 
    
    
On Error GoTo 0
    
    str_Path_Dest = "C:\TESTFOLDER"
    str_FileName = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 5)  
    
    str_DestPathName = str_Path_Dest & "\" & str_FileName & ".xlsm"
    
    
   
        Set foFS = New Scripting.FileSystemObject
        Call foFS.CopyFile(ThisWorkbook.FullName, str_DestPathName, True)
       
        Set xApp = New Excel.Application
        xApp.DisplayAlerts = False
        xApp.EnableEvents = False
       
        Set xWbk = xApp.Workbooks.Open(str_DestPathName, ReadOnly:=True)
         
  
        xWbk.SaveAs str_Path_Dest & "\" & str_FileName, xlOpenXMLWorkbook
        xWbk.Close

Sine the Filename contains the date with dots 01.01.2019 it saves my workbook as pdf but I cannot not open it. And the name becomes "Test 01.01" instead of "Test 01.01.2019"
But changing the filename to "Test 01-01-2019" works perfectly.
 
Last edited:
Upvote 0
Oops, it should be
Code:
fileName = Left(ThisWorkbook.Name, InStrRev(ThisWorkbook.Name, ".") - 1)
 
Upvote 0
Hi Fluff tha does not work either. Please look at my post above. It has dot problems in the date.
 
Upvote 0
Hi Macropod the filename is extracted correctly, also in my code, but during SaveAs it has problems with the date. The workbook is saved as "Test 01.01" and has a weird format (looking as pdf but type is excel)
 
Upvote 0
Well, since you haven't posted any code indicating how the PDF is generated, we can't comment on that.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top