billandrew

Well-known Member
Joined
Mar 9, 2014
Messages
743
Good Evening

Looking for some assist here. I am saving a workbook whichcontains several worksheets. When the new file is created there are two issues.

1. Message indicating to save the new file as an xlsx not amacro enabled file.

2. The new Worksheet the sheets have been grouped.

How can I avoid each of the above.

The code I am currently working with is:

Code:
Sub SaveE()
Dim Mypath As String
Dim Filename As String
Mypath = Environ("USERPROFILE") & "\Desktop\"
Filename = CreateObject("Scripting.FileSystemObject").GetBaseName(ActiveWorkbook.Name)
Sheets.Select
ActiveWorkbook.SaveAs Filename:=Mypath & " " & Filename & " " & ".xlsx", FileFormat:=51
End Sub

 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
What happens with

Code:
Sub SaveE()
Dim Mypath As String
Dim Filename As String
Mypath = Environ("USERPROFILE") & "\Desktop\"
Filename = CreateObject("Scripting.FileSystemObject").GetBaseName(ActiveWorkbook.Name)
'Sheets.Select
ActiveWorkbook.SaveAs Filename:=Mypath & " " & Filename & " " & ".xlsm", FileFormat:=52
End Sub

not sure why you have the & " " & in there?
 
Last edited:
Upvote 0
Try this

Code:
Sub SaveE()
  Dim Mypath As String
  Dim Filename As String
[COLOR=#0000ff]  Application.DisplayAlerts = False[/COLOR]
  Mypath = Environ("USERPROFILE") & "\Desktop\"
  Filename = CreateObject("Scripting.FileSystemObject").GetBaseName(ActiveWorkbook.Name)
  ActiveWorkbook.SaveAs Filename:=Mypath & " " & Filename & " " & ".xlsx", FileFormat:=51
End Sub
 
Upvote 0
The & " " & was used as a spacer in another code of mine, not relevant here.Thank You Mark works perfect.
 
Upvote 0
Your saving it as the new file name and extension not creating a new workbook so it is still open but renamed.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,685
Members
448,977
Latest member
dbonilla0331

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top