Consulting

Results 1 to 6 of 6

Thread: wildcard character is not working while opening excel file

  1. #1

    wildcard character is not working while opening excel file

    Hi,

    iam using below code (by using wildcard character "*" ) to open excel file. but it showing error

    kpath = ThisWorkbook.Path & "\"
    Workbooks.Open Filename:=kpath & "usd project*.xlsx"

    Error: Run-time error '1004':
    "Sorry, we couldn't find C:\Users\syed\Desktop\pipeline\usd project*.xlsx. Is it possible to moved, renamed or deleted?"


    regards
    syed
    Last edited by syed_iqbal; 04-22-2017 at 02:46 PM.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Why are you using a wild card to open a file like that?

    Did you want to open a FileOpen dialog box and pick a file to open that matches the mask "usd project*.xlsx" ?
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    HI,

    thank you for reply. I want to open the file automatically by using filepath only. there are some files like "usd project pipeline", "gbp project pipeline", "inr project pipeline", "chn project pipeline". from these files, i want to open "usd project pipeline". pls help.
    Last edited by syed_iqbal; 04-22-2017 at 03:42 PM.

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Quote Originally Posted by syed_iqbal View Post
    HI,

    thank you for reply. I want to open the file automatically by using filepath only. there are some files like "usd project pipeline", "gbp project pipeline", "inr project pipeline", "chn project pipeline". from these files, i want to open "usd project pipeline". pls help.

    Why not just ...

    kpath = ThisWorkbook.Path & "\"
     Workbooks.Open Filename:=kpath & "usd project pipeline.xlsx"
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    your code is working. my doubt is, Can't we open the file by using wildcard character.

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    If you have this ...


    Workbooks.Open Filename:=kpath & "usd project pipeline*.xlsx"

    and there are files named ...

    usd project pipeline 2015.xlsx
    usd project pipeline 2016.xlsx
    usd project pipeline 2017.xlsx

    how would Excel know which one to open?

    Now if you wanted to open ANY and ALL files that matched "usd project pipeline*.xlsx", there are ways to do that. Just not using the .Open like you used. You would need a Dir() loop
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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