macro free save sub

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I am using the sub below to send out a single sheet to a new workbook on our network drive, in effect making a "back-up" copy for auditors to review. It works great but I always get the pop-up asking me if I want to make it macro free or enabled. Ideally it would be macro free, but I can live with either option, I just do not want the pop-up to appear anymore. Going through the macro recorder I cannot seem to figure out what syntax I need to default this to macro-free. Can anyone guide me on this one?

Also, our company folder protocol is date_file name, but as you can see on the sub I have it as filename_date, I am tanking on flipping those around as well. Putting the date stamp syntax in front did not work, or I used the wrong syntax. Any help on that would be appreciated as well - many thanks.


Code:
Sub ExportReport()
'
' ExportReport Macro
'
  Dim wb As Workbook
  
  Sheets("Emergency Lighting Log").Copy
  Set wb = ActiveWorkbook
  With wb
    .SaveAs "N:\Facilities\DeptData\EH&S\Compliance and EHS\Facilities Inspections\Emergency Lighting\Emergency Lighting Report  " & Format(Now, "yy_mmdd") & ".xlsx"
    '.Close False
  End With
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Add the file format to your saveAs:
Rich (BB code):
.SaveAs "N:\Facilities\DeptData\EH&S\Compliance and EHS\Facilities Inspections\Emergency Lighting\Emergency Lighting Report  " & Format(Now, "yy_mmdd") & ".xlsx" FileFormat:= 51
 
Upvote 0
Thanks JoeMo for the quick reply, Here is my new code but I am still getting the pop-up, did I put it in the wrong place or did I leave out a character or two?

Code:
Sub ExportReport()
'
' ExportReport Macro
'
  Dim wb As Workbook
  
  Sheets("Emergency Lighting Log").Copy
  Set wb = ActiveWorkbook
  With wb
    .SaveAs "N:\Facilities\DeptData\EH&S\Compliance and EHS\Facilities Inspections\Emergency Lighting\Emergency Lighting Report  " & Format(Now, "yy_mmdd") & ".xlsx", FileFormat:=51
    
    .Close True
  End With
End Sub
 
Upvote 0
Try:

Code:
With wb
    Application.DisplayAlerts = False
    .SaveAs _
        "N:\Facilities\DeptData\EH&S\Compliance and EHS\Facilities Inspections\Emergency Lighting\Emergency Lighting Report  " _
        & Format(Now, "yy_mmdd") & ".xlsx", FileFormat:=51
    .Close True
    Application.DisplayAlerts = True
  End With
 
Upvote 0
Thanks JoeMo, for the continuing help. The applications event sounds great, I have never used that before; I will add that to my book of knowledge. I have changed my code to the following but I am getting an object error on the "Applications.DisplayAlerts = False" event. When I disable this step the code runs fine, so I guess the sub doesn't know what the object is, wouldn't that be Excel? Do I need to dim the application or something? Not sure why the sub does not know what the object is....

(I do always try to figure these things out before I reply back, but I am still learning...)

Code:
Sub ExportReport()

  Dim wb As Workbook
  
  Sheets("Emergency Lighting Log").Copy
  Set wb = ActiveWorkbook
  With wb
    Applications.DisplayAlerts = False
    .SaveAs _
         "N:\Facilities\DeptData\EH&S\Compliance and EHS\Facilities Inspections\Emergency Lighting\Emergency Lighting Report  " _
          & Format(Now, "yy_mmdd") & ".xlsx", FileFormat:=51
   .Close True
   Applications.DisplayAlerts = True
  End With
End Sub
 
Upvote 0
Thanks JoeMo, for the continuing help. The applications event sounds great, I have never used that before; I will add that to my book of knowledge. I have changed my code to the following but I am getting an object error on the "Applications.DisplayAlerts = False" event. When I disable this step the code runs fine, so I guess the sub doesn't know what the object is, wouldn't that be Excel? Do I need to dim the application or something? Not sure why the sub does not know what the object is....

(I do always try to figure these things out before I reply back, but I am still learning...)

Code:
Sub ExportReport()

  Dim wb As Workbook
  
  Sheets("Emergency Lighting Log").Copy
  Set wb = ActiveWorkbook
  With wb
    Applications.DisplayAlerts = False
    .SaveAs _
         "N:\Facilities\DeptData\EH&S\Compliance and EHS\Facilities Inspections\Emergency Lighting\Emergency Lighting Report  " _
          & Format(Now, "yy_mmdd") & ".xlsx", FileFormat:=51
   .Close True
   Applications.DisplayAlerts = True
  End With
End Sub
It's Application.DisplayAlerts not Applications.DispalyAlerts.

In case you are not aware, the best way to incorporate code that's been posted is to copy the code directly from your browser and paste it where required. Saves typing and avoids typos.
 
Upvote 0
Thanks JoeMo, it works fine. I almost always copy/paste the code in to sub, but then I sometimes manually re-type it in so that I can look a the syntax more closely and get muscle memory going. I am really trying to understand all of the little characters and learn what they are for, in this case I inadvertently added the "s"; and I did not pick it back up when I was trying to figure out what I had typed wrong. It's been a long couple of weeks...

Sorry for the inconvenience and I am extremely thankful for your assistance - Rick
 
Upvote 0
Thanks JoeMo, it works fine. I almost always copy/paste the code in to sub, but then I sometimes manually re-type it in so that I can look a the syntax more closely and get muscle memory going. I am really trying to understand all of the little characters and learn what they are for, in this case I inadvertently added the "s"; and I did not pick it back up when I was trying to figure out what I had typed wrong. It's been a long couple of weeks...

Sorry for the inconvenience and I am extremely thankful for your assistance - Rick
You are welcome. It's never an inconvenience to help.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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