Save a macro file in a new file without the macros

MrsFixIt

New Member
Joined
Apr 15, 2016
Messages
18
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am stuck.
I need to save the file without macros and attach it to an email/
I cannot get any of your examples to work/
If you have another option, I will take it.

VBA Code:
Dim OlApp As Object
Set OlApp = CreateObject("Outlook.Application")
Dim NewMail As Object
Set NewMail = OlApp.CreateItem(0)
Dim TempFilePath As String
Dim FileFullPath As String
Dim MyWb As Workbook

Dim TempFileName As String 'A portion of the file is hardcoded below
Dim CName As String 'Replaces initials in the file name
       CName = Sheets("Script").Range("K1").Value
Dim xStrDate As String 'Date/time custom format stamp for file
       xStrDate = Format(Now, "_hh-mm_yyyymmdd")
Dim xStrDate2 As String 'Date/time custom format stamp for email text
      xStrDate2 = Sheets("Script").Range("L1").Value
Dim FileNew As String
Dim CallNums As String 'Number of calls in email text
       CallNums = Sheets("Script").Range("J1").Value

Set MyWb = ThisWorkbook



With Application
              .ScreenUpdating = False
             .EnableEvents = False
             .DisplayAlerts = False
End With





'Save your workbook in your temp folder of your system below code gets the full path of the temporary folder

'in your system

TempFilePath = Environ$("temp") & "\"
TempFileName = "Class" & CName & xStrDate

ActiveWorkbook.SaveAs Filename:=TempFilePath & TempFileName & ".xlsx", FileFormat:=51

'Complete path of the file where it is saved
FileFullPath = TempFilePath & FileNew

'Now save your current workbook at the above path
MyWb.SaveAs FileFullPath

With NewMail

.To = "first person"
.CC = "second person"
' .BCC = "third person "

.Subject = "class file " & Date

.Body = "Good morning. Here is my file with " & CallNums & " class from last night's session from " & xStrDate3 & " to " & xStrDate2 & ". " & vbNewLine & vbNewLine_

.Attachments.Add FileFullPath '--- full path of the temp file where it is saved
.Display 'or use .Display to show you the email before sending it.

End With
 
Last edited by a moderator:
I think you're right, the original code was using SaveAs not SaveCopyAs.
I meant to ask. I assume as it's saving a copy of the current file that the directory to save it in is all that is required.
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Thanks. I changed the xlsm into a xtlm and everything is working fine. the new xlsx is macro-free and the template is ok.
the only thing left is the Kill FileFullPath is not working and for security reasons, the data cannot be left in the temp file
 
Upvote 0
Not working isn't really helpful. Is there an error message generated?

Some points to check.
Is the file open.
Can you manually delete it when the kill fails. That will give you a clue to whether Outlook has locked the file. It would be released when the mail is sent.
 
Upvote 0
hi.
you guys gave me enough help that made it possible for me to leave and visit my grandchildren. THANKS so much.
You are correct and the file is still open as an email attachment.
Also, the file is created by a night shift and they are borrowing a desk which is why I cannot do any manual cleanup.
It stalls at the FullPathKill with no message and no data in the variable.
I will try the TempPath and see how it goes.

And again, thanks.
 
Upvote 0
I'll take a look if you post the latest code you are using now.
 
Upvote 0

Forum statistics

Threads
1,215,030
Messages
6,122,762
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top