choose xls or xlsm?

Trevor3007

Active Member
Joined
Jan 26, 2017
Messages
493
good evening,

I currently use the following vb:-

Sub savetab()
'
' savetab Macro
'
ActiveWorkbook.SaveAs Filename:="C:\times" & Application.PathSeparator & ActiveWorkbook.Sheets(1).Name
'

However i can only send this to my recipients as an xls...but before send the final draft, i need to use the other VB/macros which are contained within the workbook. Is it possible to save but chose either xlsm or xls?

many thanks in advance.
KR
Trevor 3007




End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,332
Office Version
365
Platform
Windows
How about
Code:
Sub SaveChoose()
 If MsgBox("Do you want to save as xls?", vbYesNo) = vbYes Then
   ActiveWorkbook.SaveAs "C:\Users\DaveC\Desktop\test\Fluff" & Application.PathSeparator & ActiveWorkbook.Sheets(1).Name & ".xls", 56
Else
   ActiveWorkbook.SaveAs "C:\Users\DaveC\Desktop\test\Fluff" & Application.PathSeparator & ActiveWorkbook.Sheets(1).Name & ".xlsm", 52
End If

End Sub
 
Last edited:

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,510
Office Version
2010
Platform
Windows
How about
Code:
Sub SaveChoose()
  If MsgBox("Do you want to save as xls?", vbYesNo) = vbYes Then
    ActiveWorkbook.SaveAs "C:[B][COLOR="#FF0000"]\[/COLOR][/B]Users[B][COLOR="#FF0000"]\[/COLOR][/B]DaveC[B][COLOR="#FF0000"]\[/COLOR][/B]Desktop[B][COLOR="#FF0000"]\[/COLOR][/B]test[B][COLOR="#FF0000"]\[/COLOR][/B]Fluff" & Application.PathSeparator & ActiveWorkbook.Sheets(1).Name & ".xls", 56
  Else
    ActiveWorkbook.SaveAs "C:[B][COLOR="#FF0000"]\[/COLOR][/B]Users[B][COLOR="#FF0000"]\[/COLOR][/B]DaveC[B][COLOR="#FF0000"]\[/COLOR][/B]Desktop[B][COLOR="#FF0000"]\[/COLOR][/B]test[B][COLOR="#FF0000"]\[/COLOR][/B]Fluff" & Application.PathSeparator & ActiveWorkbook.Sheets(1).Name & ".xlsm", 52
  End If
End Sub
Why did you use Application.PathSeparator when you hard-code the back slash (your path separator) in the earlier part of the text string? Maybe you would want to do it this way instead...
Code:
Sub SaveChoose()
  If MsgBox("Do you want to save as xls?", vbYesNo) = vbYes Then
    ActiveWorkbook.SaveAs Replace("C:\Users\DaveC\Desktop\test\Fluff\" & ActiveWorkbook.Sheets(1).Name & ".xls", "\", Application.PathSeparator), 56
  Else
    ActiveWorkbook.SaveAs Replace("C:\Users\DaveC\Desktop\test\Fluff\" & ActiveWorkbook.Sheets(1).Name & ".xlsm", "\", Application.PathSeparator), 52
  End If
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,332
Office Version
365
Platform
Windows
I simply copied the OP's code & changed the path to test.
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,510
Office Version
2010
Platform
Windows
I simply copied the OP's code & changed the path to test.
Okay, I see that, so maybe my comment should be directed through to the OP... if you hard-coded the path separator, then you apparently know what it is and, as such, do not need to use Application.PathSeparator, rather, you can simply hard-code the same path separator directly... on the other hand, if you are not sure of the user's path separator, then you should probably use coding similar to what I posted in Message #3 where I use a hard-coded back space throughout the text string and then replace it with the Application.PathSeparator afterwards.
 

Trevor3007

Active Member
Joined
Jan 26, 2017
Messages
493
How about
Code:
Sub SaveChoose()
 If MsgBox("Do you want to save as xls?", vbYesNo) = vbYes Then
   ActiveWorkbook.SaveAs "C:\Users\DaveC\Desktop\test\Fluff" & Application.PathSeparator & ActiveWorkbook.Sheets(1).Name & ".xls", 56
Else
   ActiveWorkbook.SaveAs "C:\Users\DaveC\Desktop\test\Fluff" & Application.PathSeparator & ActiveWorkbook.Sheets(1).Name & ".xlsm", 52
End If

End Sub

Many thanks & works a treat. Your help has been very much appreciated.:cool:
 

Forum statistics

Threads
1,082,369
Messages
5,365,049
Members
400,819
Latest member
Gossow

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top