+ Reply to Thread
Results 1 to 30 of 30

Button for Exporting Worksheets

  1. #1
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Button for Exporting Worksheets

    Dear Forum,

    I have an Excel file that splits Bill of Materials (BOM) explosions into the correct templates for our ERP system. We copy-paste the BOM of our customers in worksheet "BOM INSERT", we fill in a few data points in "INSTRUCTIONS", and the data automatically fills in Worksheets "BOM UPLOAD" and "PRODUCT UPLOAD".

    I want a button in the "INSTRUCTIONS" tab and if you click on it, it simply downloads "BOM UPLOAD" and "PRODUCT UPLOAD" as separate files. I managed to find a few examples online and on this forum on how to do so, but it does not seem to work the way I want it to. With one I have to define a path, but that path is not universal for everyone that will use this file, it just needs to come in their Download folder for easy and quick upload into the ERP system. It should work for Mac and Windows users. The second issue was that I could not figure out how to download two worksheets instead of just one.

    I hope anyone can help, thank you greatly!
    Last edited by TBRM Group; 01-26-2022 at 07:28 AM.

  2. #2
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Singular button for downloading two worksheets

    I found the following on https://www.extendoffice.com/documen...-workbook.html.

    Besides the code not working, using the original path of the original to save the two files is also fine by me if a universal Download path is not possible. I wish it would work the way you download something from the internet, simply go to the Download folder, and if there are multiple you get the (#) behind it. But I see no single page referring to that being a possibility.

    Please Login or Register  to view this content.
    Last edited by TBRM Group; 01-25-2022 at 05:48 AM.

  3. #3
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Singular button for downloading two worksheets

    I have been trying and searching the web and testing different macros for the last hours, no luck so far. Hope there is someone that can help me out!

  4. #4
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Button for Exporting Worksheets

    I the worksheets that you want to turn into workbooks are in the file that contains the code then the below will split the sheets into workbooks and place them in your download folder:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Button for Exporting Worksheets

    Hi CheeseSandwich,

    I am getting the error message:

    Run-time error '1004':
    Method 'SaveAs' of object '_Workbook' failed.

    Any idea why this is the case? I originally thought it might be in the \ or / because I am using a Mac right now compared to most users of this Excel that use Windows. But changing it in xPath or in SaveAs did not change the error message.

  6. #6
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Button for Exporting Worksheets

    If you run the below does it give you your download folder?

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Button for Exporting Worksheets

    It does not open my download folder if that is what you are asking. It gives me a message "\Downloads"
    Attached Images Attached Images

  8. #8
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Button for Exporting Worksheets

    I see, this must be a Mac thing then, as you probably guessed i do not use Mac.

    What does the below return if you run the sub "RightFolder"

    Please Login or Register  to view this content.
    Code modified from: https://macexcel.com/examples/filesa...pecialfolders/ - Ron de Bruin
    Last edited by CheeseSandwich; 01-25-2022 at 10:09 AM.

  9. #9
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Button for Exporting Worksheets

    If I run the code above I get the same pop-up as previously, just without the message. Only the OK button.

  10. #10
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Button for Exporting Worksheets

    Sorry there was a mistake in the else part of the code above, the below has been rectified:

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Button for Exporting Worksheets

    Still the same pop-up without any information in it..

  12. #12
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Button for Exporting Worksheets

    Does the main code work if we put the files in the same place as the spreadsheet with the code?

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Button for Exporting Worksheets

    Hi! Yes, it works. However, there are three issues. Issue one is that I had to remove "\" from the code otherwise I had the same error as before. Once I did that it worked but the file did not come into the folder my own file was in, but the folder where my folder is in. So the folder itself is called A&T, in folder A&T I have folder BOM, within folder BOM I have my BOM Excel file. But now the two Excel files that are created from this code are in folder A&T. Very odd. The third issue is that the name is now BOMBOMUPLOAD and BOMPRODUCTUPLOAD. So I assume it is reading the BOM from the path, but is not actually applying it... very weird.

  14. #14
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Button for Exporting Worksheets

    Maybe that will change if we peplace all of the \ for / in the path

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Button for Exporting Worksheets

    Unfortunately still the exact same. If I copy your code I get the error message. if I remove the "/" in the line SaveAs it works, but again with BOMBOMUPLOAD as title

  16. #16
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Button for Exporting Worksheets

    Hi, I got some news. I got it to work! I went to search for my Download folder. It is "/users/'USER'/Downloads/" I found out that "USERPROFILE" does not work, but it has to be "USER" as than I got the right feedback. I am however scared that this will not work for Windows users, could you help me out there? Maybe somehow to make this compatible? As you could try this out on yours. Thank you so much so far!

    Please Login or Register  to view this content.

  17. #17
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Button for Exporting Worksheets

    Great news, just what we needed.

    Below is some untested code, interested to see what response you get in the immediate window?

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Button for Exporting Worksheets

    On the first try, it seemed to work and I got the message that it had downloaded. However, it had not. I thought I'd try to delete the ones I downloaded previously. Once I did and I ran it again, it did work. I don't think this has anything to do with what you added to the code, so I think that is successful, however, it does not replace or overwrite the previously downloaded file with the same name. Is there a way we can fix that?

  19. #19
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Button for Exporting Worksheets

    I added a \ to the xPath for the windows part, was this included on your test. I added it about 2 minutes after i posted it?

    Was it on Windows or Mac?

  20. #20
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Button for Exporting Worksheets

    Oh no I did not see that, I just ran it and it works like a charm. But only if I remove the files first from my Download folder. All my testing is on Mac, do not have access to a Windows currently

  21. #21
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Button for Exporting Worksheets

    Does it behave any different if we swap the / for : in the Mac xPath?

    Please Login or Register  to view this content.

  22. #22
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Button for Exporting Worksheets

    Yes, nothing happens. I get the error message but no files (even if I empty the download folder)

  23. #23
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Button for Exporting Worksheets

    I still have a suspicion that the Mac bit is not saving in the right place as the code overwrites the files at my end using the windows version of the xPath.

    The below includes a KILL command to delete the file before it saves the new version - theory is it will delete the file before saving the new one.

    I am not a big fan of KILL though so run it with caution (tested my end and removes correct files)

    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Button for Exporting Worksheets

    It works!! I guess it is needed for Mac maybe? I ran a different code yesterday and I did get the message if I wanted to replace it, so somehow it is possible. The code is below, I don't see any big difference with it. I just tested it again, and it does not replace it, but it does give me the message if I want to replace it because it already exists.

    Edit: Nevermind it does, but it just does not add a new one and replaces the old one, it modifies the existing one with that name. The 'Date Added' remains the same. but 'Date Modified' changes
    Please Login or Register  to view this content.
    Last edited by TBRM Group; 01-26-2022 at 06:36 AM.

  25. #25
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Button for Exporting Worksheets

    Sorry I think I am having a moment, Application.DisplayAlerts = False is already in the code so thats why we are not getting the message as it is being suppressed by that line. If you comment them lines out you get the warning message.

    I suppose it can be your choice now, have the message pop up (code will error if they press No/ Cancel though - would need handling) or keep the kill command.

    Still does not explain why the files were not being saved over though..

    When Application.DisplayAlerts = False is active on Mac it may have a different default option:
    Windows - overwrite file as a default
    Mac - don't overwrite the file as default
    I am guessing at the above as i have nver worked on a Mac

  26. #26
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Button for Exporting Worksheets

    Aha interesting, I just made the discovery that it does work without the KILL switch, but it just does not get added as a new file to my Download folder. So it stays in position at lets say 'Date Added: 11:40' but it is 'Modified by 11:41' if I re-run it. I don't know if this is a problem, if you have to keep searching for this file every few days and you may downloads many things, it might be a problem

  27. #27
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Button for Exporting Worksheets

    That reply was still on the other. Okay, that is interesting. Weird that there is so much difference. I think I will keep the kill switch for now with my testing, but the primary users are Windows users so that should be fine there. Thank you greatly!!

  28. #28
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Button for Exporting Worksheets

    Yes that is what it does on my machine, it only updates the timestamp for the file to state that it has been resaved.

    I did spot that there is the ability to download a file that is hosted on the internet using FollowHyperlink, i think this makes the computer download the file as if you were downloading and file from the internet. For this though you would need your spreadsheets to be hosted somwhere to be downloaded. Not sure if this would be an option?

  29. #29
    Registered User
    Join Date
    11-10-2021
    Location
    Netherlands
    MS-Off Ver
    Office365
    Posts
    34

    Re: Button for Exporting Worksheets

    Ahh that would be great however that wouldn't work here, the BOM will get duplicated and thrown around many many projects, none of it is hosted anywhere

  30. #30
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: Button for Exporting Worksheets

    I see, well good luck with the code you have, let me know if you have any issues.

+ 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. Downloading example worksheets posted here
    By Zephyr_Sky in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 09-08-2020, 10:01 AM
  2. Mulitple IF statements in 1 singular cell
    By Ray T in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-17-2017, 07:39 AM
  3. Replies: 8
    Last Post: 06-11-2017, 01:55 AM
  4. Replies: 9
    Last Post: 12-23-2016, 10:54 PM
  5. Remove S At End Of Word To Make Singular
    By theblade24 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-10-2016, 04:03 PM
  6. [SOLVED] Search for Singular Yellow Row
    By trevor2524 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-12-2014, 02:18 PM
  7. Replies: 0
    Last Post: 03-15-2005, 10:06 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