Force users to save as .xlsm or pdf only

Mcoca

New Member
Joined
Dec 7, 2019
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,

This thread is related and inspired on an old one: Force users to save as .xlsm or xltm only.

In any case, I tried to replicate the code for XLSM and PDF format only. No luck. Although the two options are available, the PDF one didn't produce any good file. I would like to ask you if it is possible to make this code work. Thank you very much!

VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim txtFileName As String

If SaveAsUI = True Then
Cancel = True
txtFileName = Application.GetSaveAsFilename(fileFilter:="Excel Macro-Enabled Workbook (*.xlsm), *.xlsm, PDF Files (*.pdf), *.pdf", Title:="Save As...")

If txtFileName = False Then
MsgBox "Action Cancelled", vbOKOnly
Cancel = True

Exit Sub
End If

Application.EnableEvents = False
ThisWorkbook.SaveAs Filename:=txtFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
Application.EnableEvents = True

End Sub
 

Attachments

  • Imagen1.png
    Imagen1.png
    32.3 KB · Views: 33

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I'm just putting this out there.
You cannot save a workbook as a PDF.

You should control what & where the workbook is saved as, instead of using the getsaveas dialog box, it will be quite annoying very quickly.
 
Upvote 0

Forum statistics

Threads
1,223,880
Messages
6,175,157
Members
452,615
Latest member
bogeys2birdies

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