Solved

Excel .....ActiveWorkbook.SaveAs

Posted on 2016-10-27
12
31 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 17

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 17

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
 

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 17

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Closing Comment

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

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 17

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 17

Expert Comment

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

757 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now