Solved

Excel .....ActiveWorkbook.SaveAs

Posted on 2016-10-27
12
134 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 19

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 19

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 19

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 19

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 19

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 19

Expert Comment

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Use Windows Task Scheduler to print a Word document weekly so your printer ink won't dry out.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

729 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