+ Reply to Thread
Results 1 to 5 of 5

how to open no fixed name (*.xls*) format in VBA

  1. #1
    Registered User
    Join Date
    12-14-2009
    Location
    Chennai, India
    MS-Off Ver
    Excel 2007
    Posts
    19

    Thumbs up how to open no fixed name (*.xls*) format in VBA

    Hi,

    I have open a workbook and copy the data from that workbook to another workbook.

    Here the problem is workbook name is not fixed. How to oepn that workbook.
    I used the belwo statement but giving error "no file name"

    Please Login or Register  to view this content.
    The Markets is the starting name of the file after that no fixed name.
    It might be .xls extenstion or .xlsx extension that's why I kept .xls*



    Thanks in advance,
    Venkat
    Last edited by venkiatmaruthi; 01-06-2010 at 06:51 AM.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: how to open no fixed name (*.xls*) format in VBA

    Don't think you can use wildcards when opening a file.

    It's a bit long winded but this might help, adapted from another post I answered ealier.

    Please Login or Register  to view this content.
    Dom
    Last edited by Domski; 01-05-2010 at 11:47 AM. Reason: Shortened code
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    12-14-2009
    Location
    Chennai, India
    MS-Off Ver
    Excel 2007
    Posts
    19

    Thumbs up Re: how to open no fixed name (*.xls*) format in VBA

    Quote Originally Posted by Domski View Post
    Don't think you can use wildcards when opening a file.

    It's a bit long winded but this might help, adapted from another post I answered ealier.

    Please Login or Register  to view this content.
    Dom



    Thanks for your sugguestion Domski.

    Even I used your code but no use still same error is coming when opening the file. But Dir() function found that the file is available.

    I understand the problem. The excel file is coming from SAP tool so I think it is saved in a different format. When I open the file manually and do the SAVE AS with other name and type as Micorsoft excel file. Now if I try to open the newly named file then it is working.


    Thanks in advance,
    Venkat.

  4. #4
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: how to open no fixed name (*.xls*) format in VBA

    Venkat

    What's the value of myFile when you step thru the code (after the myFile = Dir...) line? If you are getting "No file found" then it suggests that Dir isn't identifying the file to open. What is the full name and path of the file that SAP is outputting that you are expecting to open (please give an example of an actual SAP outputted file, not one you've created yourself).

    Richard
    Richard Schollar
    Microsoft MVP - Excel

  5. #5
    Registered User
    Join Date
    12-14-2009
    Location
    Chennai, India
    MS-Off Ver
    Excel 2007
    Posts
    19

    Thumbs up Re: how to open no fixed name (*.xls*) format in VBA

    Quote Originally Posted by RichardSchollar View Post
    Venkat

    What's the value of myFile when you step thru the code (after the myFile = Dir...) line? If you are getting "No file found" then it suggests that Dir isn't identifying the file to open. What is the full name and path of the file that SAP is outputting that you are expecting to open (please give an example of an actual SAP outputted file, not one you've created yourself).

    Richard
    I foudn the solution really now, I thought the error is because the file was coming from SAP sheet. But the problem here is __
    variable myFile is getting only the file name(Markets_nov09.xls), not the full path. Dir is only returning filename. So we have to add the directory(where it is located) also to that filename then it is opening the file without any problem.
    Last edited by venkiatmaruthi; 01-11-2010 at 08:29 AM.
    Thanks in advance,
    Venkat

+ 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