+ Reply to Thread
Results 1 to 13 of 13

Copy from a workbook without using path or file name

  1. #1
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    309

    Cool Copy from a workbook without using path or file name

    Hi
    I have a master workbook in which I want to enter a line of competitor information from the many (Excel based) entry forms we receive. The entry forms come in having been saved under all different Team names.

    The first row of a sheet within the entry form contains several columns of information that I want to transfer to the Master Sheet.

    I have some code that copies the row from the entry form and successfully pastes it in to the correct sheet on the master workbook.

    [Code]
    Public Sub copy_wb()
    Dim copy_from As Range
    Dim copy_to As Range

    Set copy_from = Workbooks(Test_Form).Worksheets(Test_Entry).UsedRange
    Set copy_to = Workbooks(MASTER_ENTRY).Worksheets(TEST_PASTE).Range("B" & Rows.Count).End(xlUp).Offset(1, 0)

    copy_from.Copy Destination:=copy_to
    Application.CutCopyMode = False

    End Sub
    [\Code]

    However, my problem is that the entry forms that I'm copying the information out of will not have consistent names or maybe even paths. Also, there may be many (40 or 50) entry forms in a folder at the end of a path.

    If I have the Master open and open one of the entry forms would it be possible to make the copy_from find and copy from the entry form that is open on the desktop? i.e something along the lines of Copy_from Workbooks 1 = Desktop."*" ??

    Not holding my breath, but it would be really useful if there is a way of doing this!

    Thanks
    Last edited by Frankie_The_Flyer; 06-09-2017 at 12:51 AM.

  2. #2
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Copy from a workbook without using path or file name

    hi
    If the workbook is open, you could simply use

    Please Login or Register  to view this content.
    and perhaps use a simple loop to cycle through all open workbooks

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Copy from a workbook without using path or file name

    This will loop through all open workbooks and copy from each one to the workbook that contains the code.

    Please Login or Register  to view this content.

    Alternatively, you could have it loop through all files in a folder or have it prompt the user to multi-select the files to copy from.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    309

    Re: Copy from a workbook without using path or file name

    Thanks for the quick responses but we're not quite there yet!
    With both the Master and one Entry form open I get a Run time 9 error - Subscript out of range warning with the "Set copy_from = Workbooks(1).Worksheets(Test_Entry).UsedRange" highlighted in yellow.
    I should maybe add that it works if I put the actual entry form workbook name in instead of (1). Should the entry form be actually saved to the desk top, or doesn't it matter? What about if it was opened directly from arriving as an attachment to an email?
    Last edited by Frankie_The_Flyer; 06-09-2017 at 03:47 AM.

  5. #5
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Copy from a workbook without using path or file name

    Hi Frankie
    it could be that workbook(1) is your master book, not the source book, so you may get an error trying to copy from that.
    AlphaFrog's code should solve that, as it loops through all open books except the active one

  6. #6
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    309

    Re: Copy from a workbook without using path or file name

    Unfortunately AlphaFrogs input has the same result but with

    Please Login or Register  to view this content.
    highlighted in yellow. ("Test_Copy" is the correct wording. I incorrectly wrote "Test_Paste" in the info above. I'd changed the wording in the code before trying it).

    Run time 9 error - Subscript out of range

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Copy from a workbook without using path or file name

    Put quotes around "Test_Entry" if that is the actual source sheet name.
    Also, do you have any workbooks opened that do not have a "Test_Entry" sheet?

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 06-09-2017 at 06:04 AM.

  8. #8
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    309

    Re: Copy from a workbook without using path or file name

    Ha! That easy!! Thanks Chaps! All good now.

  9. #9
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    309

    Re: Copy from a workbook without using path or file name

    Hit a bit of a snag here in that the copy seems to only go across a row to the first blank cell so if someone doesn't put in (say) their address, I don't get anything after that. I've also got a header row, (which I've managed to take out of the copy instruction) but I was wondering if I could use that as the UsedRange to indicate the number of columns across the row for the instruction?
    Another slight issue is that the info in the row in Test_Entry can be from a link to another sheet so is a formula. The paste into the Destination worksheet needs to be Values, but if I put PasteSpecial(xlPasteValues) at the end of the line, it all falls over!

    This is what I have so far..........

    Please Login or Register  to view this content.
    Thanks again for any assistance you may be able to offer!

  10. #10
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Copy from a workbook without using path or file name

    Try this. It's not tested, but it should copy all columns, omit the header row, and paste values.

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 06-11-2017 at 02:30 AM.

  11. #11
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    309

    Re: Copy from a workbook without using path or file name

    This works well with my test sheet (Test_Copy) apart from that the paste action into Test_Copy overwrites the last row of text in the sheet. It needs to paste one row lower please.

    However, when I try it on the actual entry form I've been creating it doesn't copy anything. (Only the new form and the Master open). The New entry form has an entry form that is traditional (so very reluctant to change it) as one worksheet and a worksheet behind it (Teams & Runners Data Form Entry) that puts the information into rows to make it more useful (It's all over the place on the actual entry form!). As the actual form has drop down lists to select from and many merged cells the "Teams & Runners Data Form Entry" sheet is populated through formula relating to the correct cells in the entry form and left blank if nothing is entered in a cell (=IF('Entry Form'!L24="","",'Entry Form'!L24).
    Not sure if this is screwing up the copy paste activities??

    Actual Code I have now is....
    Please Login or Register  to view this content.
    Really appreciate the help here! (The new look message box is great too!)

  12. #12
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Copy from a workbook without using path or file name

    Quote Originally Posted by Frankie_The_Flyer View Post
    This works well with my test sheet (Test_Copy) apart from that the paste action into Test_Copy overwrites the last row of text in the sheet. It needs to paste one row lower please.
    It should paste one row below in the last used cell in column B.
    Is the cell in column B for the last row empty?


    However, when I try it on the actual entry form I've been creating it doesn't copy anything. (Only the new form and the Master open).
    Actual Code I have now is....
    As a test, comment out the worksheet name If - End If

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    309

    Re: Copy from a workbook without using path or file name

    Works like a dream thanks Alphafrog!. What a star you are!!

    And yes, "B" was empty on the test sheet. All OK with B filled in .

    Thanks again

+ 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] Use Application.GetOpenFilename and copy file path and file name into cells
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-24-2017, 10:13 AM
  2. Copy this File As (This workbook Path + Name + Phrase + (V)arriant #)
    By drgkt in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-08-2017, 07:41 PM
  3. Copy this File As (This workbook Path + Name + Phrase + (V)arriant #)
    By drgkt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2017, 06:04 PM
  4. [SOLVED] Need Copy file name and contents of that file in a specified path
    By punna111 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-12-2014, 10:37 AM
  5. Replies: 5
    Last Post: 03-21-2013, 07:34 AM
  6. [SOLVED] Get file path from a cell, run a check to see if the file has a specific sheet if yes copy
    By Martha44 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-04-2013, 03:35 AM
  7. how to set a workbook from a file name and path
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-21-2005, 05:05 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