+ Reply to Thread
Results 1 to 4 of 4

Run a SaveAs VBA formula then disable the SaveAs formula in Workbook

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-03-2019
    Location
    Victoria, Australia
    MS-Off Ver
    Office 365
    Posts
    159

    Run a SaveAs VBA formula then disable the SaveAs formula in Workbook

    Hi Excel Forum Experts,

    I have found a VBA code that works but i need it altered so that when it runs, the code in the new Macro Workbook is disabled so when the new workbook is reopen next time the code does not run. So If you have filled out data in the new macro workbook i just want it to open on next open as it would get very messy if you have to keep clicking save as and override the the file you are working on and you might end up overriding the wrong file.

    How do i alter this code to make sure it is disabled on new file after save.

    The VBA Code i am using is the followingwhich is stored in the ThisWorkbook section

    Private Sub Workbook_Open()
    Dim FileSaveAsName As Variant
    Dim intchoice As Integer
    Static saveProcess As Boolean
    Application.EnableEvents = False
    ActiveWindow.ScrollRow = 1
            Set FileSaveName = Application.fileDialog(msoFileDialogSaveAs)
    
            FileSaveName.InitialFileName = ThisWorkbook.Name
            FileSaveName.FilterIndex = 2   'select to save with a ".xlsm" extension
            intchoice = FileSaveName.Show
            If intchoice <> 0 Then
                FileSaveName.Execute
            End If
    
    Application.EnableEvents = True
    End Sub
    TIA for any assistance

    Thanks
    Donald
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,534

    Re: Run a SaveAs VBA formula then disable the SaveAs formula in Workbook

    You can make the code work dependent on the name of the workbook. If the name is different from the defined one, the inside of the condition will not execute:
    Private Sub Workbook_Open()
        Dim FileSaveName As Variant
        Dim intchoice As Integer
        
        If UCase(Me.Name) = UCase("My book.xlsm") Then
            Application.EnableEvents = False
            
            Set FileSaveName = Application.FileDialog(msoFileDialogSaveAs)
    
            FileSaveName.InitialFileName = Me.Name
            FileSaveName.FilterIndex = 2   'select to save with a ".xlsm" extension
            intchoice = FileSaveName.Show
    
            If intchoice <> 0 Then
                FileSaveName.Execute
            End If
    
            Application.EnableEvents = True
        End If
    End Sub
    Artik

  3. #3
    Forum Contributor
    Join Date
    07-03-2019
    Location
    Victoria, Australia
    MS-Off Ver
    Office 365
    Posts
    159

    Re: Run a SaveAs VBA formula then disable the SaveAs formula in Workbook

    Thanks for your assistance Artik this has worked how i wanted it to.

    Thanks
    Donald

  4. #4
    Forum Contributor
    Join Date
    07-03-2019
    Location
    Victoria, Australia
    MS-Off Ver
    Office 365
    Posts
    159

    Re: Run a SaveAs VBA formula then disable the SaveAs formula in Workbook

    This post is also cross-posted over at MrExcel at the following link sorry for not making it as a cross-post.

    https://www.mrexcel.com/board/thread.../#post-6193269

    Donald

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Disable SaveAs option allow save
    By csrahul in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-11-2016, 04:43 AM
  2. [SOLVED] Disable Prompt when SaveAs (New Workbook)
    By ntitled in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-06-2014, 05:23 PM
  3. [SOLVED] Disable SaveAs On Toolbar But Allow in Macro
    By djfatboyfats in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-09-2013, 10:16 AM
  4. Disable Save/SaveAs in 2007
    By ultimastryder in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-10-2013, 10:26 AM
  5. workBook.Saveas
    By PreHistoricMan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-02-2013, 01:23 AM
  6. Disable/Enable Save,SaveAs & Sendto in File Menu based on condition
    By aravindhan_31 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-16-2011, 04:43 AM
  7. Workbook::SaveAs() in MFC - Please help!
    By ArukTheRed in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-15-2005, 12:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1