+ Reply to Thread
Results 1 to 7 of 7

Excel 2010 open workbook that is named in Cell value

Hybrid View

Malor Excel 2010 open workbook that... 05-17-2017, 06:13 AM
Olly Re: Excel 2010 open workbook... 05-17-2017, 07:50 AM
Malor Re: Excel 2010 open workbook... 05-17-2017, 08:01 AM
Olly Re: Excel 2010 open workbook... 05-17-2017, 08:08 AM
Malor Re: Excel 2010 open workbook... 05-17-2017, 08:15 AM
Malor Re: Excel 2010 open workbook... 05-17-2017, 08:20 AM
Olly Re: Excel 2010 open workbook... 05-17-2017, 08:49 AM
  1. #1
    Registered User
    Join Date
    05-17-2017
    Location
    Rotterdam
    MS-Off Ver
    Excel 2010
    Posts
    42

    Excel 2010 open workbook that is named in Cell value

    Hi Users,

    I'm new here and I'm Dave from The Netherlands. I'm 24 years old and working now 6 months with Excel and I must say I'm very impressed what's possible with it.

    Just my question:

    I've 2 workbooks open just for example :

    1. Masterdata
    2. Pickup list with variable date for example Pickup list May 17 , and the day after, Pickup list May 18

    So the May and date number is variable. I need to open it (2.) from my Masterdata sheet with an macro and put an vlookup in this sheet.

    I've made an cell (b3) in the masterdata with : ="Pickup list "&TEXT(C2;"[$-409]mmm d").
    C2 is the today date with =TODAY()

    So could someone tell me how to switch to the named workbook showed in cell B3.

    It could be a little confusing so if you have any question, please let me know!

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Excel 2010 open workbook that is named in Cell value

    Try:
    Sub OpenDailyWorkbook()
        Dim sPath As String
        Dim sFileName As String
        Dim wb As Workbook
        
        sPath = "C:\Temp\"  ' change as necessary
        sFileName = "Pickup List " & Format(Date, "mmm d") & ".xlsx"
        If Dir(sPath & sFileName) = "" Then
            MsgBox "File " & sPath & sFileName & " was not found", vbExclamation + vbOKOnly
        Else
            Set wb = Workbooks.Open(sPath & sFileName)
        End If
    
    End Sub
    (you don't need the TODAY() formula or the formatted name in cells B3 and C2 - the code does that formatting for the current date)
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    05-17-2017
    Location
    Rotterdam
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Excel 2010 open workbook that is named in Cell value

    Thanks Olly,

    Only just 1 problem, the date format is in Dutch and it needs to be in english. So instead of "Mei" it need to be "May".

    Thanks!

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Excel 2010 open workbook that is named in Cell value

    Aha! Then change this line:
        sFileName = "Pickup List " & Application.WorksheetFunction.Text(Date, "[$-409]mmm d") & ".xlsx"

  5. #5
    Registered User
    Join Date
    05-17-2017
    Location
    Rotterdam
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Excel 2010 open workbook that is named in Cell value

    Hi Olly,

    EDIT : Sorry it works, thanks for your help!
    Last edited by Malor; 05-17-2017 at 08:16 AM. Reason: wrong reaction

  6. #6
    Registered User
    Join Date
    05-17-2017
    Location
    Rotterdam
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Excel 2010 open workbook that is named in Cell value

    Just 1 last question Olly,

    Is this also possible to switch to this sheet because sometimes the user already opened it and when it's already open, the macro will get in error.

    Thanks in advance.

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Excel 2010 open workbook that is named in Cell value

    Okay, this version will check to see if the workbook is already open - if not, then try to open it - then activate it.
    Sub OpenDailyWorkbook()
        Dim sPath As String
        Dim sFilename As String
        Dim wb As Workbook
        
        sPath = "C:\Temp\"  ' change as necessary
        sFilename = "Pickup List " & Application.WorksheetFunction.Text(Date, "[$-409]mmm d") & ".xlsx"
        
        On Error Resume Next
        Set wb = Workbooks(Dir(sPath & sFilename))
        If Err Then Err.Clear
        On Error GoTo Terminate
        If wb Is Nothing Then Set wb = Workbooks.Open(sPath & sFilename)
        wb.Activate
    
    Terminate:
        If Err Then
            MsgBox "File " & sPath & sFilename & " was not found", vbExclamation + vbOKOnly
            Err.Clear
        End If
    End Sub

+ 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. excel 2010 how do I reference current workbook and named range in a formula
    By clairh2011 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-24-2015, 08:28 AM
  2. Macro in Excel 2010 - can't open personal workbook with the VBA code to correct
    By Sparkmeister in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-12-2013, 03:34 PM
  3. Replies: 2
    Last Post: 09-10-2013, 10:55 PM
  4. How do I reference another workbook and open a specific sheet named in a cell
    By shabooty542362 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-19-2013, 04:50 PM
  5. Replies: 3
    Last Post: 03-29-2013, 12:35 PM
  6. Open excel 2010 workbook in excel 2007 missing references
    By Snoopy2003 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2011, 07:01 PM
  7. excel 2010 very slow to open/save workbook
    By bebe123 in forum Excel General
    Replies: 10
    Last Post: 01-06-2011, 11:10 AM

Tags for this Thread

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