Solved

Excel .....ActiveWorkbook.SaveAs

Posted on 2016-10-27
12
70 Views
Last Modified: 2016-10-28
Hi experts,
Need help putting these two lines into VBA for me.
 
ActiveWorkbook.SaveAs
and
Workbook.Settings.CheckComptiliblity = False

Here is all the code I am trying to insert this into.

Sub SaveASFile()
Dim SaveAsPath As String
Dim Ans As String
Dim fileName As String

>>>>>>>  ActiveWorkbook.SaveAs fileName:="C:\Users\pike\Desktop\backup\"

fileName = Replace(ThisWorkbook.Name, ".xlsm", ".xls")
Ans = MsgBox("Do you want to Save A Copy?", vbQuestion + vbYesNo, "Confirm Please!")
If Ans = vbYes Then
   Application.DisplayAlerts = False
   
 >>>>>>>>>    Workbook.Settings.CheckComptiliblity = False
   
   ThisWorkbook.SaveAs SaveAsPath & fileName, 51
   Application.DisplayAlerts = True
End If
End Sub

Open in new window

0
Comment
Question by:chris pike
  • 6
  • 6
12 Comments
 
LVL 18

Expert Comment

by:Roy_Cox
ID: 41862534
Hi Chris

Do you mean this

Option Explicit

Sub SaveASFile()
    Dim Ans As String
    Dim fileName As String
    Dim SaveAsPath As String

    SaveAsPath = "C:\Users\pike\Desktop\backup\"
    '>>>>>>>  ActiveWorkbook.SaveAs fileName:="C:\Users\pike\Desktop\backup\"

    fileName = Replace(ThisWorkbook.Name, ".xlsm", ".xls")
    Ans = MsgBox("Do you want to Save A Copy?", vbQuestion + vbYesNo, "Confirm Please!")
    If Ans = vbYes Then
        Application.DisplayAlerts = False

        '>>>>>>>>>    Workbook.Settings.CheckCompatiliblity = False
        ThisWorkbook.CheckCompatibility = False
        ThisWorkbook.SaveAs SaveAsPath & fileName, 51
        Application.DisplayAlerts = True
    End If
End Sub

Open in new window

0
 

Author Comment

by:chris pike
ID: 41862804
If it works than yes..
Will check it out as soon as I can string 5 minutes together,
Thanks
Chris
0
 
LVL 18

Expert Comment

by:Roy_Cox
ID: 41863398
No problem.

A couple of amendments. The below code will work with .xlsx,.xlsm,.xlsb and it switches compatability checking back on

Option Explicit


Sub SaveASFile()
    Dim Ans As String, fileName As String, SaveAsPath As String

    SaveAsPath = "C:\Users\pike\Desktop\backup\"
    '>>>>>>>  ActiveWorkbook.SaveAs fileName:="C:\Users\pike\Desktop\backup\"
''/// ".xls*" should work with .xlsx,.xlsm,.xlsb
    fileName = Replace(ThisWorkbook.Name, ".xls*", ".xls")
    Ans = MsgBox("Do you want to Save A Copy?", vbQuestion + vbYesNo, "Confirm Please!")
    If Ans = vbYes Then
        Application.DisplayAlerts = False
        '>>>>>>>>>    Workbook.Settings.CheckCompatiliblity = False
        ThisWorkbook.CheckCompatibility = False
        ThisWorkbook.SaveAs SaveAsPath & fileName, 51
         ThisWorkbook.CheckCompatibility = True
        Application.DisplayAlerts = True
    End If
End Sub

Open in new window

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:chris pike
ID: 41863972
OK Roy,
I am having trouble with the functionality of the saved copy.
I think I will need to keep it a XLSM file.
I tried to tinker with the code to leave it as the same file type.....    :(   but no dice.
Wish I was better at this stuff.
 And what if I wanted to rename the copy, is that doable??

Thanks so Much Roy
Chris
0
 
LVL 18

Accepted Solution

by:
Roy_Cox earned 500 total points
ID: 41864046
Looks like you are changing to .xls. If so you will lose functionality such as Tables and others. Try this

Option Explicit

Sub SaveASFile()
    Dim Ans As String, fileName As String, SaveAsPath As String

    SaveAsPath = "C:\Users\pike\Desktop\backup\"
  
    Ans = MsgBox("Do you want to Save A Copy?", vbQuestion + vbYesNo, "Confirm Please!")
    If Ans = vbYes Then
    ''/// ask user for new name for workbook
    fileName = Application.InputBox("Plese enter a new name for the saved copy", "Workbook name")
    ''/// if no name entered default to this workbook's name with a file stamp
    If fileName = vbNullString Then fileName = ThisWorkbook.Name & Format(Date, "ddmmyyyy")
        Application.DisplayAlerts = False
        ThisWorkbook.SaveAs SaveAsPath & fileName & "xlsm", 52
        Application.DisplayAlerts = True
    End If
End Sub

Open in new window

0
 

Author Comment

by:chris pike
ID: 41864131
This is a perfect solution. Thanks so much Love it.....
Thanks Roy.
Chris

Have a fantastic Weekend
0
 

Author Closing Comment

by:chris pike
ID: 41864132
Awesome Thanks so much.
0
 
LVL 18

Expert Comment

by:Roy_Cox
ID: 41864154
pleased to help again
0
 

Author Comment

by:chris pike
ID: 41864168
If I had your skills, I would be designing apps and would be a millionaire for sure.
0
 
LVL 18

Expert Comment

by:Roy_Cox
ID: 41864193
I wish I could make millions with my VBA skills!
0
 

Author Comment

by:chris pike
ID: 41864397
The ideas, and logic behind the VBA can translate easily to APP development.
I have designed some pretty cool programs from EE help, that do a great job on site...But the logic behind them can be made into apps for sure.
0
 
LVL 18

Expert Comment

by:Roy_Cox
ID: 41864906
I've never looked at App development.
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Dynamic Chart Range 13 37
Delete all empty columns using VBA 7 42
Excel VBA 4 27
VBA – How to autofit row height with merged cells? 12 11
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question