Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Excel .....ActiveWorkbook.SaveAs

Posted on 2016-10-27
12
Medium Priority
?
306 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 22

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 22

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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 22

Accepted Solution

by:
Roy Cox earned 2000 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 22

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 22

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 22

Expert Comment

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

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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 demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

963 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