+ Reply to Thread
Results 1 to 2 of 2

VBA to Open File (filename contains current date) & copy Sheet to active workbook

Hybrid View

jlstidham VBA to Open File (filename... 08-12-2013, 10:10 PM
ajryan88 Re: VBA to Open File... 08-12-2013, 10:50 PM
  1. #1
    Registered User
    Join Date
    07-12-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    4

    VBA to Open File (filename contains current date) & copy Sheet to active workbook

    I need help!
    i'm trying to open a file where the filename contains the current date, (i.e. "report 8-12-2013). I have no problems opening it by adding the date but i'd like to be able to open it daily by just clicking button.
    next i'd like to copy sheet 2 into my active workbook in tab named "data". can someone please help?!

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: VBA to Open File (filename contains current date) & copy Sheet to active workbook

    Hi,

    Place a button anywhere within your workbook (it doesn't have to be the "data" tab if you don't want it to be), and then use this code for the Click event:
    Private Sub CommandButton1_Click()
        Dim WB As Workbook
        
        'This will automatically determine the name of the file you want to open
        'If the file resides in a different directory, change "ThisWorkbook.Path"
        'Make sure the file extension is correct at the end of the next line also
        Set WB = Workbooks.Add(ThisWorkbook.Path & "\report " & Month(Date) & "-" & Day(Date) & "-" & Year(Date) & ".xlsx")
        
        'Copy all cells from "Sheet2" in the daily workbook
        WB.Worksheets("Sheet2").Cells.Copy
        
        'Paste the contents into the "data" worksheet in this workbook
        ThisWorkbook.Worksheets("data").Range("A1").PasteSpecial
        
        'Clear the clipboard of the data that you just copied
        Application.CutCopyMode = False
        
        'Close the daily report workbook
        WB.Close
        
        'Select cell "A1" on the "data" worksheet
        ThisWorkbook.Worksheets("data").Range("A1").Select
    End Sub
    Hope this helps

    Don't forget to click the star and mark the thread as solved if I have helped you
    Attached Files Attached Files
    Last edited by ajryan88; 08-12-2013 at 10:53 PM. Reason: Attached sample workbooks

+ 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] COPY from an open workbook with particular sheet and columns to active workbook
    By purin0c0 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-12-2012, 03:57 PM
  2. Copy a sheet into a new book and save file name as the current date.
    By Jay3 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 07-10-2009, 06:59 AM
  3. Command button - to copy active sheet and not save current workbook
    By vjboaz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-22-2008, 05:23 PM
  4. [SOLVED] Rename active sheet with current file name
    By transferxxx@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-11-2006, 01:35 PM

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