+ Reply to Thread
Results 1 to 4 of 4

VBA does not execute save

Hybrid View

  1. #1
    Registered User
    Join Date
    08-30-2019
    Location
    Finland
    MS-Off Ver
    2016
    Posts
    4

    VBA does not execute save

    Hi,

    I have a code that works just fine, except for one big flaw: I am trying to save a file, but it doesnt "execute" the save. In other words, the everything is fine before the "save as" -dialog box and after it. But it doesnt save.

    Could someone help me with this?

    Sub ExportABC()
    
        Dim xWs As Worksheet
        Dim Rng As Range
        Dim varResult As Variant
        
        Set Rng1 = Worksheets("ABC").Range("ABC")
        Set Rng = Range("ABC")
        Application.Sheets.Add
        Set xWs = Application.ActiveSheet
        Rng.Copy Destination:=xWs.Range("A2")
        Rng1.Copy Destination:=xWs.Range("A1")
    
        ActiveSheet.Copy
        varResult = Application.GetSaveAsFilename(, _
            FileFilter:="Excel Files (*.xlsx), *.xlsx")
        If varResult <> False Then
        Application.DisplayAlerts = False
        ActiveWorkbook.Close
        ActiveSheet.Delete
        Application.DisplayAlerts = True
        Worksheets("ABC").Activate
        
        MsgBox "Text"
        
        Else
        
        Application.DisplayAlerts = False
        ActiveWorkbook.Close
        ActiveSheet.Delete
        Application.DisplayAlerts = True
        Worksheets("ABC").Activate
        
        MsgBox "Text"
        
        End If
        
    End Sub
    Thank you!

  2. #2
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: VBA does not execute save

    Hi
    Add this line to your code
     If varResult <> False Then
            ActiveWorkbook.SaveAs filename:=varResult, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    Last edited by mohadin; 09-01-2019 at 03:15 PM.

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,610

    Re: VBA does not execute save

    @Mohadin
    Please use code tags ( the #button) instead of PHP tags. Thanks

  4. #4
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: VBA does not execute save

    Quote Originally Posted by Pepe Le Mokko View Post
    @Mohadin
    Please use code tags ( the #button) instead of PHP tags. Thanks
    Done
    Sorry for that

+ 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. Replies: 1
    Last Post: 04-29-2016, 11:55 AM
  2. Execute a macro in a closed workbook, or open and execute without the user noticing
    By cearaujo123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-09-2015, 06:44 PM
  3. code to execute a keyboard shortcut or to execute a toolbar button
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2015, 12:16 PM
  4. Loop to execute SAVE code as defined number of times
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-10-2013, 08:15 AM
  5. Command line for open excel, insert a sheet, execute a macro, save file exit?
    By uschxc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-26-2012, 12:28 PM
  6. [SOLVED] execute macro; save it and close using Application.OnTime
    By ina in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-12-2006, 12:25 PM
  7. [SOLVED] getting vba shell command to execute batch and save output to a file
    By Mad Scientist Jr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-28-2006, 10:10 AM

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