Prevent Change in File Extension?

Duvnjak

New Member
Joined
Aug 14, 2003
Messages
27
Hello,

Is there an effective way to prevent a user from changing the file extension of a file? For example, if a file needs to remain .xls I want to prevent a user from changing it to .xlsx, etc.

I assume I would need to add code to the Workbook_BeforeSave event? Or is there a better way?

Thank you in advance!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi:

I found this code which should be placed in ThisWorkbook. It might do the trick for you...

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.EnableEvents = False
  Dim vFile
  Dim strDirectoryPath As String
    
   If SaveAsUI Then
vFile = Application.GetSaveAsFilename("C:\temp\Sample.xls", "Excel files (*.xls),*.xls")
   If TypeName(vFile) = "Boolean" Then
    Cancel = True
    Application.EnableEvents = True
       Exit Sub  ' user cancelled
End If
   strDirectoryPath = "C:\temp\"
   If Dir(strDirectoryPath, vbDirectory) = "" Then MkDir strDirectoryPath
   ActiveWorkbook.SaveAs vFile, FileFormat:=56
   Application.EnableEvents = True
   saveProcessStarted = False
Cancel = True
     Exit Sub
   End If
Application.EnableEvents = True
 End Sub


Good Luck,
Mark
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,775
Members
452,353
Latest member
strainu

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