choose xls or xlsm?

Trevor3007

Well-known Member
Joined
Jan 26, 2017
Messages
675
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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:
Upvote 0
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
 
Upvote 0
I simply copied the OP's code & changed the path to test.
 
Upvote 0
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.
 
Upvote 0
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:
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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