+ Reply to Thread
Results 1 to 24 of 24

Refer to Workbook name using wilcard

  1. #1
    Registered User
    Join Date
    06-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    68

    Refer to Workbook name using wilcard

    Hello,

    I have a workbook with a button that does the following: User downloads an excile file from the internet, then activates a workbook i created that has a button, that basically copies all the info on the downloaded file to it. The button on a workbook has the following code:

    Please Login or Register  to view this content.
    The problem is that the "randsf" workbook is a temporary file downloaded from the internet that is only named "randsf[1]" if it's the first file downloaded by the user since starting their computer, otherwise it could be named randsf[6], and the user will then get the error message.

    Obviously i've found that it's not as simple as changing the reference to "randsf*", and i've also tried the following (found online sometime ago??) with no success:

    Please Login or Register  to view this content.

    Any help would be appreciated. This is an issue that has reared i's ugly head every couple months for the last year or so, and just cant seem to figure it out.
    Last edited by MaddyG; 01-08-2014 at 10:56 AM. Reason: better explanation

  2. #2
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Refer to Workbook name using wilcard

    Why don't you delete the downloaded file, after you have done with it ?
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Refer to Workbook name using wilcard


    Hi,

    instead of using a temporary file downloaded from the net, open the net source file !

    Regards !

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Refer to Workbook name using wilcard

    the InStr method should work, what is the value of "name"?

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Refer to Workbook name using wilcard

    Maybe:

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Refer to Workbook name using wilcard

    @JOHN H. DAVIS,

    does the OP need the last downloaded file or the all the downloaded file like "*randsf*

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Refer to Workbook name using wilcard

    Quote Originally Posted by xlbiznes View Post
    @JOHN H. DAVIS,

    does the OP need the last downloaded file or the all the downloaded file like "*randsf*
    No. I maybe wrong but I assumed there would only be one open file "*randsf*". Workbooks is a collection of open files.

  8. #8
    Registered User
    Join Date
    06-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Refer to Workbook name using wilcard

    xlbinez: it's always deleted or closed once after the process is over with. I suppose i could write that into the macro, but i'm not sure how that will address teh current issue.

    Marc L: That would be great and definately the bet solution, but something i'll have to approach IT about it. I try to avoid them if possible as they always look at me like I have 3 he
    ads when I ask them a question and their real protective of their domain. The minuses may outway the pluses.

    yudluger: 'name = Workbook.name

    John H. Davis: I trid to incorporate your suggestions as follows and it's going to the ErrMessage even if the temp file is open

    Please Login or Register  to view this content.
    I removed the part you had that activated the temp workbook, because I only want to refer to it for copying it. I want the workbook with the button that does all that to remain activated.
    Last edited by MaddyG; 01-08-2014 at 12:01 PM. Reason: small clarification

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Refer to Workbook name using wilcard

    Does this work?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Refer to Workbook name using wilcard

    Maybe:

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Refer to Workbook name using wilcard

    That does actually appear to work - but i need to check on teh users computer (since this always worked when I did it, but never when they did).
    I want the error message to show if there are NO open workbooks with a name like "randsf".

    It appears this runs the process fine, but will always generate the error message on the last loop perfomed. Can you help with this also?

    Please Login or Register  to view this content.

  12. #12
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Refer to Workbook name using wilcard

    could this be the issue of case (upper or lower case)

    can you try changing this line of code
    from :
    Please Login or Register  to view this content.
    to:
    Please Login or Register  to view this content.

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Refer to Workbook name using wilcard

    If you remove this line of code, which I left out on purpose , do you get any errors?
    Please Login or Register  to view this content.
    If you don't then try using xlbzines suggestion to make the check case insensitive.

  14. #14
    Registered User
    Join Date
    06-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Refer to Workbook name using wilcard

    Hi John - thanks for 2nd try. I ran this and got the follwoing error:

    Compile Error: Invalid or unqualified reference"

    and it highlighted the ".Range" prior to the
    Please Login or Register  to view this content.
    portion of your code.

  15. #15
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Refer to Workbook name using wilcard

    Perhaps:

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    06-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Refer to Workbook name using wilcard

    Norie: I removed and got the same error message, tried Johns suggestion to make the case insensitive (even though it's always named lowercase), and still same. Process of copying/pasting works, but still generates error on completion of the macro.

  17. #17
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Refer to Workbook name using wilcard

    Can you post the debug output of all wb.name in your for loop

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    06-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Refer to Workbook name using wilcard

    HI John - equally as effective as Norie's suggestion. Does the same thing, runs approrpiately, but throws up the error message with the last loop every time it's run.

  19. #19
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Refer to Workbook name using wilcard

    If you used the exact code I posted you wouldn't get any error messages.

    The code would loop through all the open workbooks in and if the one you want isn't find that would be it, the code would end.

  20. #20
    Registered User
    Join Date
    06-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Refer to Workbook name using wilcard

    I'm not sure if this is what you're looking for but pasted that in teh immediate window and got "Run-time error '424': Object required"

  21. #21
    Registered User
    Join Date
    06-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Refer to Workbook name using wilcard

    Norie - right. I just think it would be good if the user clicks this update button and forgot to download the temp excel file, that an error notified them that they should log on, download this file and retry. Otherwise, nothing appears to happen at all and maybe they think there were just no updates/changes from the previous time they performed this process.

  22. #22
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Refer to Workbook name using wilcard

    Quote Originally Posted by MaddyG View Post
    HI John - equally as effective as Norie's suggestion. Does the same thing, runs approrpiately, but throws up the error message with the last loop every time it's run.
    Is there really a need for the error message in the code?

    Please Login or Register  to view this content.

  23. #23
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Refer to Workbook name using wilcard

    If you want a message if the file isn't found.
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    06-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Refer to Workbook name using wilcard

    Thanks - that's exactly what i was looking for.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to refer to the workbook where the macro when another workbook is open during runtime?
    By jonelamora in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-04-2012, 11:21 PM
  2. Indirect to refer to a different workbook?
    By pclive in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-03-2011, 03:27 PM
  3. how to refer to new workbook
    By aretai in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-06-2010, 07:26 AM
  4. Word wilcard replace help needed.
    By Kempston in forum Word Formatting & General
    Replies: 2
    Last Post: 12-09-2009, 06:25 AM

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