+ Reply to Thread
Results 1 to 5 of 5

Changing File Extensions.

  1. #1
    Registered User
    Join Date
    04-11-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2007 and 2003
    Posts
    3

    Question Changing File Extensions.

    I am editing some VB code in my excel workbook that opens other excel files. The problem is that there are many other users of these files and some have Excel 2003 and some have Excel 2007 and some have Excel 2010. When the code opens the file filename.xls. It can't find the file when the newer versions of excel have saved the file and it is now filename.xlsm or filename.xlsx. Do I have to use file extensions in the code when opening and manipulating the file?

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Changing File Extensions.

    you should use the proper file extension in your VBA code. If you the have filename and the folder, you could use the Dir command within VBA to get the extension.

    You could also use a Dialog within VBA to pick the file (and its extension).
    Gary's Student

  3. #3
    Registered User
    Join Date
    04-11-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2007 and 2003
    Posts
    3

    Re: Changing File Extensions.

    The file extension changes depending on who was the last one to save the file? Is there some simple easy way to have it open the file with either file extension? The macros that are having this problem run in different versions of excel and the files in question run in different versions of excel. I am a novice programmer in VB so please make explanation easy and give me an example. Thanks!

  4. #4
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Changing File Extensions.

    Here is an example.
    The scenario is that we know the folder (C:\TestFolder) and we know the workbook name (Book2), but we don't know the extension (.xls or .xlsx or .xlsm)

    This macro:
    1. searches the folder
    2. finds a file with the correct name
    3. sets a variable to the complete name (name + extension)
    4. opens the file


    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-11-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2007 and 2003
    Posts
    3

    Re: Changing File Extensions.

    I think this will work. Thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1