Results 1 to 24 of 24

Refer to Workbook name using wilcard

Threaded View

  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:

    On Error GoTo ErrMsg
      With Workbooks("randsf[1].xls").Worksheets(1)
          .Range("A2", .Range("A" & Rows.Count).End(xlUp)).Resize(, 15).Copy _
            Destination:=ActiveWorkbook.Sheets("Sheet2").Range("A2")
     End With
       Exit Sub
    
    ErrMsg:
       MsgBox ("There is no randsf workbook curently open")
    
    
    End Sub
    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:

    On Error GoTo ErrMsg
    ' If InStr(1, name, "randsf[") > 0 Then
    '   With ActiveWorkbook.Worksheets(1)
    '       .Range("A2", .Range("A" & Rows.Count).End(xlUp)).Resize(, 15).Copy _
    '           Destination:=ActiveWorkbook.Sheets("Sheet2").Range("A2")
    '   End With
    'End If

    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

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