Solved

Excel .....ActiveWorkbook.SaveAs

Posted on 2016-10-27
12
116 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

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!

Question has a verified solution.

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

Suggested Solutions

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 …
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

732 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