+ Reply to Thread
Results 1 to 4 of 4

Complex SaveAs and Kill Macro Help

  1. #1
    Registered User
    Join Date
    06-17-2013
    Location
    Tacoma, WA
    MS-Off Ver
    Excel 2013
    Posts
    2

    Question Complex SaveAs and Kill Macro Help

    Hello folks! Long time lurker but finally decided to ask some questions here since I see you guys have an awesome community...!

    I have a somewhat interesting project where I am taking badly formatted data from an export to .XLS, converting it to .CSV format (to strip the crazy groupings and other issues), manipulating the formatting again for column headers and other settings, then saving it again in .XLSX format. I only really need the final output of the .XLSX file, and I want to save it to a specific folder but have the name based on the existing sheet name or file name...!

    Currently it basically works (by running the macro from a .XLSM file), but only deletes the generated .CSV file and leaves the original garbage .XLS file there. The files are also saved in the Documents folder (default) and I cannot figure out how to save all the files into a subfolder. I have tried using the following for the path: "%homepath%\documents\ExcelReports" but I could never get this to function with generated file names. Maybe my syntax is just wrong, or I am going about this the wrong way... If anyone can help or make comments it would be much appreciated!

    I have cut and spliced and tested to the best of my ability and ended up with this:

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 06-18-2013 at 07:51 PM. Reason: Added CODE tags, as per Forum Rules. Take a moment to read the Forum Rules in the menu bar above. Thanks.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Complex SaveAs and Kill Macro Help

    Perhaps all this missing it the path to the file? The kill command is being fed a filename, but probably not the path TO that file.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    06-17-2013
    Location
    Tacoma, WA
    MS-Off Ver
    Excel 2013
    Posts
    2

    Re: Complex SaveAs and Kill Macro Help

    Quote Originally Posted by JBeaucaire View Post
    Perhaps all this missing it the path to the file? The kill command is being fed a filename, but probably not the path TO that file.
    Wow that was FAST! Thanks for the reply. I would agree, but the Kill command does function for the sCSVName file, though it does not have a path defined...? I would love to specify the path and then reference the file name, but as I mentioned I have yet be able to specify the SaveAs location of the files while letting it base the file name on the ActiveSheet or ActiveWorkbook name...

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Complex SaveAs and Kill Macro Help

    Declare a string variable, put the path you want to use in that variable, then you can use it throughout the rest of your code.

    Since you always want to delete these files when you're done, there's no reason to fiddle with filenames either. Just pick a "junk" filename and use it for saving, opening and deleting.


    snippets
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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