VBA Calling WorkbookName minus the .xls

Posted on 2006-03-30
Last Modified: 2012-06-21
How do I grab a workbook name without the file extension?

This is what I get with ThisWorkBook.Name = PM.xls

What I want is just = PM


Question by:troyhalsey
    LVL 142

    Accepted Solution

    left(ThisWorkBook.Name, len(ThisWorkBook.Name)-4)
    LVL 92

    Expert Comment

    by:Patrick Matthews
    Hi Troy,

    SomeVar = Left(ThisWorkbook.Name, InStrRev(ThisWorkbook.Name, ".xls", -1, vbCompareText) - 1)


    LVL 28

    Expert Comment

    Left(ThisWorkBook.Name,Instrrev(ThisWorkBook.Name,".") -1)

    Author Comment

    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    Let me clarify that the other 2 suggestions are more generic in the sense that excel can open documents that are not necessarily .xls but can have any other extensions...
    LVL 92

    Expert Comment

    by:Patrick Matthews
    > Let me clarify that the other 2 suggestions are more generic

    Well, really Vinny's was the only generic solution--my suggestion was still looking for a XLS extension :)


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now