+ Reply to Thread
Results 1 to 4 of 4

Custom *and* Original SaveAs Dialog Box Popping Up

Hybrid View

  1. #1
    Registered User
    Join Date
    09-20-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    13

    Custom *and* Original SaveAs Dialog Box Popping Up

    Hi guys

    This is probably going to have a really simple solution that I've entirely failed to notice. However, I have a custom saveas dialog box Module which forces the file to save as .xlsm and gets the file name from certain cells.

    I've called that module from an If function which checks the filename first.

    Basically, this is me trying to stop the custom save as box from popping up unless it's the original (template) document. I was having problems with subsequent revisions and saves to the resulting file were also popping up the save-as box.

    I seem to have fixed that, and it does seem to only be working if the file name matches. However, it then *also* pops up the original save as box, thereby making a user have to save the file twice.

    If anyone can help me figure out why the original is still coming up I'd love to know!

    The Module is called CPOSave and the code was written by OllieB on this site so I'm familiar with it but don't necessarily fully understand it. Code is:
    Sub MySaveAs()
    On Error Resume Next
    Dim pvt_str_SaveAsName As String
    
    '# cancel the original dialog
       Cancel = True
       
    '# get the desired name and path, if none specified, exit the routine
    With Application.FileDialog(msoFileDialogSaveAs)
          
          .Title = "Custom Save As"
          .ButtonName = "Save"
          .InitialView = msoFileDialogViewDetails
          .InitialFileName = ThisWorkbook.Worksheets("Sheet1").Cells(6, 6).Value & " " & Format(Now, "MMMM YYYY")
             
          If Not .Show Then
             Exit Sub
          Else
             pvt_str_SaveAsName = .SelectedItems(1)
          End If
             
       End With
       
    '# replace the extension specified by the user with the fixed extension as required - and save the workbook
       pvt_str_SaveAsName = Left$(pvt_str_SaveAsName, InStrRev(pvt_str_SaveAsName, ".") - 1) & ".xlsm"
       Application.EnableEvents = False
       ThisWorkbook.SaveAs pvt_str_SaveAsName, xlOpenXMLWorkbookMacroEnabled
       Application.EnableEvents = True
    
    End Sub
    And the code that calls it is:
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If LCase(Left$(ActiveWorkbook.Name, 13)) = LCase("Template Name") Then
        Call CPOSave.MySaveAs
    Else
        Exit Sub
    End If
    End Sub

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,973

    Re: Custom *and* Original SaveAs Dialog Box Popping Up

    Your Cancel = True line needs to be in the BeforeSave routine.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    09-20-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Custom *and* Original SaveAs Dialog Box Popping Up

    Legend! Thank you

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,973

    Re: Custom *and* Original SaveAs Dialog Box Popping Up

    Glad to help.

+ 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. SaveAs dialog box on Mac
    By malcmail in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 3
    Last Post: 04-14-2014, 09:36 AM
  2. [SOLVED] How do I stop a warning dialog box from popping up, using VBA
    By woodbridge1965 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-27-2013, 12:41 PM
  3. SaveAs PDF Dialog Box
    By zplugger in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-21-2011, 05:00 PM
  4. Replies: 0
    Last Post: 02-18-2009, 11:37 PM
  5. [SOLVED] Keep original wkbk open after SaveAs?
    By Ed in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-02-2005, 06:06 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