PDA

View Full Version : Restricting Save As Options



jdubs
05-21-2013, 01:00 PM
Hi,
I am using the code found here on this site at article 379
to force users to enable macros upon opening the file to use the file.
There is a section in the code which limits the save as file types. Here is that section:

Private Sub CustomSave(Optional SaveAs As Boolean)
Dim ws As Worksheet, aWs As Worksheet, newFname As String
'Turn off screen flashing
Application.ScreenUpdating = False

'Record active worksheet
Set aWs = ActiveSheet

'Hide all sheets
Call HideAllSheets

'Save workbook directly or prompt for saveas filename
If SaveAs = True Then
newFname = Application.GetSaveAsFilename( _
fileFilter:="Excel Macro-Enabled Workbook (*.xlsm), *.xlsm)

If Not newFname = "False" Then ThisWorkbook.SaveAs newFname
Else
ThisWorkbook.Save
End If


'Restore file to where user was
Call ShowAllSheets
aWs.Activate

'Restore screen updates
Application.ScreenUpdating = True
End Sub
I would also like to let users save as a pdf.

I tried:
fileFilter:="Excel Macro-Enabled Workbook (*.xlsm), *.xlsm, PDF Files (*.pdf), *.pdf")
Which creates the PDF but the PDF just errors out when I try to open it. Any ideas?

I also found this bit of code which looks important to this process but I am not sure where to place it.

ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, Filename:="C:\", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
Thanks for the help!
John