+ Reply to Thread
Results 1 to 11 of 11

VBA edit help - copy data from an excel without opening the file first

  1. #1
    Registered User
    Join Date
    01-19-2017
    Location
    NYC
    MS-Off Ver
    2016
    Posts
    10

    VBA edit help - copy data from an excel without opening the file first

    I wrote the below script to move business commentary from a fixed sharepoint location into a master file. I was wondering if there is any way to adjust the code to not have to open the file im taking the commentary from?? Thanks

    Please Login or Register  to view this content.
    Last edited by TollemG; 01-25-2017 at 12:37 PM.

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

    Re: VBA edit help - copy data from an excel without opening the file first

    Hi ,
    According to the forum rules, you need to add code tags of your posted code! Please!
    ...I am not sure if I understand very well what you need, you want to copy two ranges and paste'em in the active workbook, is this correct?!
    try this, change the apth and sheet name for your needs
    Please Login or Register  to view this content.
    Last edited by john55; 01-25-2017 at 05:34 AM.
    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-

  3. #3
    Registered User
    Join Date
    01-19-2017
    Location
    NYC
    MS-Off Ver
    2016
    Posts
    10

    Re: VBA edit help - copy data from an excel without opening the file first

    thanks for the reply john, a couple of questions as im still very new to VBA.

    Please Login or Register  to view this content.
    what is the "sheet(1)" supposed to represent? and what is the "sheet1" supposed to represent? Is this the tab in the workbook im pulling the data range from or is this the destination tab? I think I did something wrong because as I updated your code I get a subscript out of range error. I believe this means im trying to reference a tab that doesn't exist. This is what I filled in

    Please Login or Register  to view this content.


    Even with the run time error this code does the exact thing my original code did.

    Please Login or Register  to view this content.
    Is there no way to reference this location and pull the data without opening the workbook? If this is not possible I think I can just add something to close the file again after the paste is done.

  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: VBA edit help - copy data from an excel without opening the file first

    Hi,
    Please Login or Register  to view this content.
    Look at the sheet name where you want to import data and change it in the code, see red color
    here
    Please Login or Register  to view this content.
    also, look at the sheet name wherw you want to paste the data-see the red color
    Please Login or Register  to view this content.
    both of them are named "BU template"?
    the code opens the workbook where you take data from, copies and closes it.

  5. #5
    Registered User
    Join Date
    01-19-2017
    Location
    NYC
    MS-Off Ver
    2016
    Posts
    10

    Re: VBA edit help - copy data from an excel without opening the file first

    Bear with me John, im clearly slow, but determined to check off the vba competency box in 2017.

    Please Login or Register  to view this content.

    currently looks like this, the "BU template" is the sheet in the workbook im exporting data from, the "BU template - EM" is where im pasting the data into.

    Something is still named incorrectly because it does not let me finish out the script to close the EM.xlsx file opened to extract the information.

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

    Re: VBA edit help - copy data from an excel without opening the file first

    first mistake, is missing teh range
    Please Login or Register  to view this content.
    check the sheet name, including any space...
    you mean is the wb still open after the coping data?

    *** add the code tags to the 1st post, please!
    Last edited by john55; 01-25-2017 at 12:25 PM.

  7. #7
    Registered User
    Join Date
    01-19-2017
    Location
    NYC
    MS-Off Ver
    2016
    Posts
    10

    Re: VBA edit help - copy data from an excel without opening the file first

    correct, it doesn't close after copying data.

    Please Login or Register  to view this content.
    this is the line that debugger identifies as error. Am I incorrectly including "" or () around sheet names? the names are pasted right out of my workbooks so spaces are correct.


    Please Login or Register  to view this content.
    does the code already know that the "wb" referenced is the one identified at the start of the code?

    Please Login or Register  to view this content.

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

    Re: VBA edit help - copy data from an excel without opening the file first

    Please Login or Register  to view this content.
    '' you have to add'em!
    yes, thw wb is set and the code knows about it! do not worry!
    perhaps someone else can help us.....

  9. #9
    Registered User
    Join Date
    01-19-2017
    Location
    NYC
    MS-Off Ver
    2016
    Posts
    10

    Re: VBA edit help - copy data from an excel without opening the file first

    Ok this is driving me crazy, spent like 2 hours trying to get this to work.

    I have a code that works like the one @john55 posted that I set up using simple record commands seen below

    Please Login or Register  to view this content.

    however, I am determined to figure out why this one will not work


    Please Login or Register  to view this content.
    My understanding is that the code application works as follows, set current sheet as active, open a separate workbook from the sharepoint location shown, take cell range d42:v44 and d47:v51 on the tab called "BU template" in the sharepoint document. Copy and paste these values into d42:v42 and d47:v47 in the active tab ("BU template - EM") in my original workbook. it will then close the sharepoint workbook.

  10. #10
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA edit help - copy data from an excel without opening the file first

    Where does it fail?
    Are you sure you have a sheet named "BU template - EM" in 'Thisworkbook'
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  11. #11
    Registered User
    Join Date
    01-19-2017
    Location
    NYC
    MS-Off Ver
    2016
    Posts
    10

    Re: VBA edit help - copy data from an excel without opening the file first

    it highlights the entire line here

    Please Login or Register  to view this content.

    and "thisworkbook" would refer to the location Im pasting the data into correct? yes I have a tab with that exact name.

+ 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] Opening text file to copy data for processing
    By CityMPLSEmpolyee in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-17-2015, 03:15 PM
  2. Replies: 1
    Last Post: 07-11-2015, 01:04 AM
  3. Copy, edit and save workbook to same location as source data file, not macro file.
    By Jasonhouse in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2014, 09:01 AM
  4. Replies: 1
    Last Post: 02-02-2014, 08:04 PM
  5. [SOLVED] Automatically Copy Data in Excel File upon opening email attachment
    By rachaelgoldman1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-20-2013, 05:21 AM
  6. Copy and paste without opening excel file
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-20-2010, 10:14 AM
  7. Copy data without opening file
    By new_to_vba in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2006, 09:20 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