Variable not defined error

drluke

Active Member
Joined
Apr 17, 2014
Messages
283
I want users to save a workbook as a macro enabled file by using this code:
Code:
Sub StartFunctional ()
Dim FileSaveName As Variant
Dim xFileName As String

    If SaveAsUI <> False Then
    Cancel = True
    xFileName = Application.GetSaveAsFilename(, "Excel Macro-Enabled Workbook (*.xlsm), *.xlsm", , "Save As xlsm file")
        End If
        
    Application.FileDialog(msoFileDialogSaveAs).Show
    End Sub


However, I am getting a 'Variable Not Defined' compile error. I have no idea, how to correct this. Can't find anything sensible that could help me.


Any advice appreciated.
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,503
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
It looks like you've taken the code from a Workbook_BeforeSave event and tried to turn it into a normal routine, in which case you need to remove the test for SaveAsUI and the Cancel = True line.
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,108,911
Messages
5,525,593
Members
409,652
Latest member
strangelyangely

This Week's Hot Topics

Top