+ Reply to Thread
Results 1 to 29 of 29

Close workbook with a fixed name

  1. #1
    Forum Contributor
    Join Date
    02-12-2018
    Location
    Clearwater, FL
    MS-Off Ver
    MS 365
    Posts
    214

    Close workbook with a fixed name

    I have this code which a report is generated and it is not a constant name except the beginning of the file name which is "_ttv-".
    Please Login or Register  to view this content.
    The problem is that it does not close the other Workbook - can someone please help me!?

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Close workbook with a fixed name

    1.
    Quote Originally Posted by Jamesraywebber85 View Post
    ... is not a constant name except the beginning of the file name which is "_ttv-".
    Please Login or Register  to view this content.
    Instead of "Dim", use:
    Please Login or Register  to view this content.
    2. If "_ttv-" is the beginning of the file, then what is "MyWorkbook2015" ?

    3.
    Please Login or Register  to view this content.
    Where did "Wb2" come from, and what is it?

    4.
    Please Login or Register  to view this content.
    All cells ? 1,048,576 rows x 16,384 columns = 17,179,869,184 cells ?

    5. Instead of:
    Please Login or Register  to view this content.
    use:
    Please Login or Register  to view this content.
    6.
    Please Login or Register  to view this content.
    7.
    Please Login or Register  to view this content.
    Where did "Wb2" come from, and what is it ?

  3. #3
    Forum Contributor
    Join Date
    02-12-2018
    Location
    Clearwater, FL
    MS-Off Ver
    MS 365
    Posts
    214

    Re: Close workbook with a fixed name

    So I have edited my code, but it does not copy the data over like it supposed to - can you take a look at this and let me know what I might be doing wrong?
    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Close workbook with a fixed name

    Please Login or Register  to view this content.
    With such code you are using any file ...!
    Please Login or Register  to view this content.
    Paste is done in Worksheets("IEX Data - CT Set 20") does exist in the active workbook or in which workbook ??
    Could you explain step by step what you want to do ?
    - Battle without fear gives no glory - Just try

  5. #5
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Close workbook with a fixed name

    Please Login or Register  to view this content.
    With such code you are using any file ...!
    Is it
    Please Login or Register  to view this content.
    you need ??


    Please Login or Register  to view this content.
    Paste is done in Worksheets("IEX Data - CT Set 20") does exist in the active workbook or in which workbook ??
    Could you explain step by step what you want to do ?

  6. #6
    Forum Contributor
    Join Date
    02-12-2018
    Location
    Clearwater, FL
    MS-Off Ver
    MS 365
    Posts
    214

    Re: Close workbook with a fixed name

    So I have included my files along with the report that runs each hour with a different file name that begins with "_ttv-". That workbook has sheet("Interaday") which needs to be copied over the "IEX Data - CT Set 20") in the workbook called "SSC Hourly Update Template".
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Close workbook with a fixed name

    What about
    Please Login or Register  to view this content.
    Last edited by PCI; 05-21-2018 at 12:26 PM. Reason: Code updated

  8. #8
    Forum Contributor
    Join Date
    02-12-2018
    Location
    Clearwater, FL
    MS-Off Ver
    MS 365
    Posts
    214

    Re: Close workbook with a fixed name

    It does not do anything either

  9. #9
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Close workbook with a fixed name

    Are you using the last code (I made some adjustments)
    Attached Files Attached Files
    Last edited by PCI; 05-21-2018 at 12:46 PM.

  10. #10
    Forum Contributor
    Join Date
    02-12-2018
    Location
    Clearwater, FL
    MS-Off Ver
    MS 365
    Posts
    214

    Re: Close workbook with a fixed name

    Yes using the latest code from post #7! The macro is in the SSC Hourly update Template which will copy the data from this "_ttv-" file and paste it into the worksheet ("IEX Data - CT Set 20")

  11. #11
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Close workbook with a fixed name

    Is it OK now ??
    Just to finish, a little cleaning
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    02-12-2018
    Location
    Clearwater, FL
    MS-Off Ver
    MS 365
    Posts
    214

    Re: Close workbook with a fixed name

    It looks good so far - thank you so much for your help!

  13. #13
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Close workbook with a fixed name

    You are welcome
    Enjoy Excel

  14. #14
    Forum Contributor
    Join Date
    02-12-2018
    Location
    Clearwater, FL
    MS-Off Ver
    MS 365
    Posts
    214

    Re: Close workbook with a fixed name

    So after a day of playing around with the code you provided. It pulls the data once and the next hour when it updates, it does not work - any ideas on this?

  15. #15
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Close workbook with a fixed name

    Try
    Code already sent in another thread ...!
    Do we agree that original data is cleaned up each time !!!
    Please Login or Register  to view this content.
    Last edited by PCI; 05-22-2018 at 11:18 AM.

  16. #16
    Forum Contributor
    Join Date
    02-12-2018
    Location
    Clearwater, FL
    MS-Off Ver
    MS 365
    Posts
    214

    Re: Close workbook with a fixed name

    Yes it is cleaned up each time.

  17. #17
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Close workbook with a fixed name

    Oh I see, in your first macro is used only files loaded in Excel then the same is done in the macro sent, is it what you want ???

  18. #18
    Forum Contributor
    Join Date
    02-12-2018
    Location
    Clearwater, FL
    MS-Off Ver
    MS 365
    Posts
    214

    Re: Close workbook with a fixed name

    I'm not sure - the file will be loaded into excel and open when we run the macro.

  19. #19
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Close workbook with a fixed name

    As you mentioned "It pulls the data once and the next hour when it updates, it does not work"
    It does not work if the file is not loaded in Excel else copy/Paste is done and file is closed
    Can you detail step by step the issue you see

  20. #20
    Forum Contributor
    Join Date
    02-12-2018
    Location
    Clearwater, FL
    MS-Off Ver
    MS 365
    Posts
    214

    Re: Close workbook with a fixed name

    So here is 2 of the hourly reports & my SSC template that runs the macro, run the macro once and then load the next hourly report and try to run the macro again - you will see that it does not pull the data like I need it to.

  21. #21
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Close workbook with a fixed name

    Yes it is working but there is a certainly a confusion about the understanding of the job to.
    What is the job today:
    Clean up sheet "IEX Data - CT Set 20"
    For all files loaded in Excel starting with "_ttv-"
    Copy and paste data from sheet "Intraday" to sheet "IEX Data - CT Set 20" at cell A1
    => it means the last file 's values will erase the previous one
    => there is no cleaning done
    => it means you will see only data for the last one and a part of the previous files if they were larger

    What is the final result you need?

  22. #22
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Close workbook with a fixed name

    Here another code where will be seen in sheet "IEX Data - CT Set 20"
    only data of the last input file sheet "Intraday"
    Is it what you want ?

    Please Login or Register  to view this content.

  23. #23
    Forum Contributor
    Join Date
    02-12-2018
    Location
    Clearwater, FL
    MS-Off Ver
    MS 365
    Posts
    214
    Quote Originally Posted by PCI View Post
    Here another code where will be seen in sheet "IEX Data - CT Set 20"
    only data of the last input file sheet "Intraday"
    Is it what you want ?

    Please Login or Register  to view this content.
    The report is ran every hour so i want it to copy the data from that report and paste it into the CT Set 20 sheet overwriting all the data there because the report from the previous hour will be on the new report.

  24. #24
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Close workbook with a fixed name

    PHP Code: 
    "The report is ran every hour so i want it to copy the data from that report and paste it into the CT Set 20 sheet overwriting all the data there because the report from the previous hour will be on the new report." 
    This is what the last macro is doing as far as the file is loaded in Excel
    It means it is up to you to load the file and trigger the macro every hour ...!

  25. #25
    Forum Contributor
    Join Date
    02-12-2018
    Location
    Clearwater, FL
    MS-Off Ver
    MS 365
    Posts
    214
    Quote Originally Posted by PCI View Post
    PHP Code: 
    "The report is ran every hour so i want it to copy the data from that report and paste it into the CT Set 20 sheet overwriting all the data there because the report from the previous hour will be on the new report." 
    This is what the last macro is doing as far as the file is loaded in Excel
    It means it is up to you to load the file and trigger the macro every hour ...!
    If the report runs and excel said there was an error with the data and repairs the information, would it not work?

  26. #26
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Close workbook with a fixed name

    PHP Code: 
    If the report runs and excel said there was an error with the data and repairs the informationwould it not work
    If Excel repaired it, it means it should reusable by Excel so it will work.
    Now if there is some difficulties, it is possible to manage the error:
    Do a display to the user, launch another job ...

  27. #27
    Forum Contributor
    Join Date
    02-12-2018
    Location
    Clearwater, FL
    MS-Off Ver
    MS 365
    Posts
    214

    Re: Close workbook with a fixed name

    I am still having trouble with this one - is there a way that we could import it based on the last updated file at this location? This is the path inwhich the file saves once we run it (C:\Users\Rwebber\WFMData\_ttv-5534267313106029378.xlsx). I was wondering could we have a code where it will look in this location and find the most recent workbook and import the data that way and then tell it to close that workbook?

  28. #28
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Close workbook with a fixed name

    OK, you want to use the last file recorded in "C:\Users\Rwebber\WFMData\", with beginning like "_ttv-"
    It means you miss to review some records: if there is several files only the last one will used ...!
    By the way, if the file where is the macro is already recorded in "C:\Users\Rwebber\WFMData\" we could use the path of this file without to mention explicitely the path "C:\Users\Rwebber\WFMData\"...!

    See next and comment
    Please Login or Register  to view this content.
    Last edited by PCI; 05-26-2018 at 05:23 AM. Reason: Code added

  29. #29
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Close workbook with a fixed name

    By the way, if your data files like "_ttv-" have in their name some time reference with could use it.
    Let's say that "_ttv-1643454077149903120.xlsx" is old than "_ttv-8659680448621142670.xlsx" and we can see it because threre is a particular inside the name, it will be very simple and clear.

+ 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 from first workbook, close open new workbook paste close
    By johncarr1952 in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 08-04-2021, 08:50 AM
  2. [SOLVED] Issue with Open, copy, close Macro - when trying to close workbook Clipboard error
    By seanpcorbett1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-13-2016, 05:14 PM
  3. [SOLVED] Auto Close Msg Box after Time Period & Close Workbook
    By GJF36 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-24-2015, 10:25 AM
  4. [SOLVED] Close Userform2 on workbook close
    By zplugger in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-12-2015, 10:24 AM
  5. [SOLVED] Code to cut cell from one workbook, close same workbook, and paste in different workbook
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 03-13-2014, 04:01 PM
  6. Disable close workbook but still force users to close thru command button
    By rathig in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-18-2013, 07:29 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