+ Reply to Thread
Results 1 to 7 of 7

Copy from closed WP selected in user from... help needed!

  1. #1
    Registered User
    Join Date
    09-04-2014
    Location
    Osijek, Croatia
    MS-Off Ver
    2010
    Posts
    4

    Copy from closed WP selected in user from... help needed!

    Hello!

    I need help with copying from selected WB.

    I have an userform which opens before code is run. In this userform, user have to select workbook which will represent data for prior year and it looks like this:

    Please Login or Register  to view this content.
    Now i have the whole path of selected file (including filename.xlsx) stated in label5 and need to copy some data from that workbook later in macro.
    In example, i need to copy range ("F12:F17") from worksheet ("BIL") in selected workbook to range("E12:E17") in worksheet ("BIL") in workbook generated with macro.

    I tried everything i could think of, but nothing worked. As i understand, i should be able to use both PYFPath and Label5 for this purpose, but i dont know how.
    I also googled for "vba copy from closed WB" but neither of results had an example with reference to workbook selected in userform.

    Please help.

    thanks!

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

    Re: Copy from closed WP selected in user from... help needed!

    Have you tried opening the workbook you want to copy from?
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Copy from closed WP selected in user from... help needed!

    Opening workbook is one possibility as Norie suggest.
    another possibility is to use ADO to retrieve data from the closed workbook using SQL. Here is sample file I have posted long time ago in another thraed
    http://www.excelforum.com/excel-prog...ml#post3619395
    If you are pleased with a member's answer then use the Star icon to rate it.

  4. #4
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: Copy from closed WP selected in user from... help needed!

    see if it helps you....
    Please Login or Register  to view this content.
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  5. #5
    Registered User
    Join Date
    09-04-2014
    Location
    Osijek, Croatia
    MS-Off Ver
    2010
    Posts
    4

    Re: Copy from closed WP selected in user from... help needed!

    thank you for your answers.
    @ buran: ADO is too complicated for me at this moment
    @ John55 and NorieOpened: i would really like to keep workbook closed.

    i know there is a simple way to copy from closed workbook:


    Please Login or Register  to view this content.
    but this way i have to type path, name and range into the code. I'd like to insert path from Label5 (which is path and name of selected workbook) into the code similar to one above.

  6. #6
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Copy from closed WP selected in user from... help needed!

    From John Walkenbach's book "Excel® 2007 Power Programming with VBA"

    Retrieving a value from a closed workbook
    VBA does not include a method to retrieve a value from a closed workbook file. You can, however, take advantage of Excel’s ability to work with linked files. This section contains a custom VBA function (GetValue, which follows) that retrieves a value from a closed workbook. It does so by calling an XLM macro, which is an old-style macro used in versions prior to Excel 5. Fortunately, Excel still supports this old macro system.

    Please Login or Register  to view this content.

    I've never used it, but maybe it will help.

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

    Re: Copy from closed WP selected in user from... help needed!

    Why can't you use the value in the label in that code?

+ 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. Copy selected data from a closed file and transfer to web
    By yojimbooo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-25-2014, 02:56 PM
  2. [SOLVED] Macro to copy non continuous ranges in closed worbooks based on user input
    By Chrispelletier in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-07-2014, 07:49 AM
  3. Copy selected range from email attachment and paste into closed workbook
    By Lisa4legin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-15-2013, 09:32 AM
  4. Copy selected range to closed workbooks using VBA
    By olives in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-12-2013, 02:04 PM
  5. Macro To Import Selected Range From Closed Workbook Only When Needed
    By jasono in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-28-2011, 06:48 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