+ Reply to Thread
Results 1 to 4 of 4

Save file to users Temp folder, attach it to email then Kill file from temp folder

  1. #1
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    453

    Save file to users Temp folder, attach it to email then Kill file from temp folder

    Hi Folks,

    I'm creating a workbook to enable our pensions team to produce reports.

    At the moment, part of the process is opening the SaveAs dialog box. (Here's my full code below - it's heavily commented so that if changes are needed and I'm not available, someone can at least follow the logic - even if it is flawed! )

    What I'd like to do instead is save the file to the users temp folder, then, after it has been attached to an email and sent, kill that file from the temp folder.

    Can anyone offer advice on how I can do this?

    Here's my code for the SaveAs dialog. I'm guessing this would be replaced with defining the Environ("TEMP") along with the variables below
    Please Login or Register  to view this content.
    and i add it to the email as follows:
    Please Login or Register  to view this content.
    I'm guessing that somehow I need to save it to the users temp file Environ("TEMP")? and then refer to that in the .Attachments.Add Activeworkbook.FullName

    At the end of the Macro, I'd add something along the lines of Kill Environ("TEMP") ActiveWorkbook.FullName

    That's my theory, I just don't know whether I need to add Dim's etc.

    Any help would be appreciated.

    MM

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,021

    Re: Save file to users Temp folder, attach it to email then Kill file from temp folder

    Activeworkbook.Fullname includes the full path and file name, so you don't need to change that. Just alter the SaveAs line to save the current workbook in the TEMP folder:

    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    453

    Re: Save file to users Temp folder, attach it to email then Kill file from temp folder

    Thanks Rorya,

    That worked a dream. I used the same code at the end of the macro to kill the file created in the temp folder:

    Please Login or Register  to view this content.
    Rep is on its way.

    Sometimes, all you need is 'nudging' in the right direction
    Last edited by MagicMan; 08-18-2022 at 08:49 AM.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,021

    Re: Save file to users Temp folder, attach it to email then Kill file from temp folder

    Glad to help.

+ 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. Replies: 2
    Last Post: 01-07-2022, 04:42 PM
  2. [SOLVED] Copy sheet on Desktop and email as attach new file created(with save/not "temp")
    By Gr33nMM in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2021, 04:39 PM
  3. attach file in an outlook email from specific folder
    By 9599lorenzo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-19-2017, 07:07 AM
  4. save temp file to my documents
    By shiftyspina in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-29-2014, 06:08 AM
  5. Replies: 8
    Last Post: 04-24-2013, 10:16 AM
  6. [SOLVED] (Email worksheet) Show MsgBox when failing to save temp file
    By timmye in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-29-2013, 11:47 PM
  7. Finding Excel temp save Folder?
    By oo0tommyk0oo in forum Excel General
    Replies: 2
    Last Post: 12-22-2010, 10:05 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