<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: GetSaveAsFilename</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2004/06/10/getsaveasfilename/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2004/06/10/getsaveasfilename/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Thu, 09 Feb 2012 19:28:40 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Aaron Reese</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/10/getsaveasfilename/#comment-66782</link>
		<dc:creator>Aaron Reese</dc:creator>
		<pubDate>Thu, 06 Oct 2011 12:14:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=618#comment-66782</guid>
		<description>&lt;p&gt;you get the same issue in Excel 2003 if the filename provided contains fullstops and the last part after the last stop does not match the filters.  If the filename does not contain any dots (i.e.) has no file extension in the name then the filtered file extension is used as the file type and the name displays correctly.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>you get the same issue in Excel 2003 if the filename provided contains fullstops and the last part after the last stop does not match the filters.  If the filename does not contain any dots (i.e.) has no file extension in the name then the filtered file extension is used as the file type and the name displays correctly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeff weir</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/10/getsaveasfilename/#comment-55017</link>
		<dc:creator>jeff weir</dc:creator>
		<pubDate>Mon, 29 Nov 2010 23:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=618#comment-55017</guid>
		<description>&lt;p&gt;Interesting...I amended this code so that instead of the filename being blank, it returns the ActiveWorkbook.Name. However, it turns out that if the filterindex setting does not &lt;em&gt;exactly&lt;/em&gt; match the filetype as the workbook currently has, then the ActiveWorkbook.Name will be enclosed in quotation marks, and if a user then selects another filetype from the &#039;Save as type&#039; dropdown this has no effect unless/until they have removed those quotation marks...that is, the file is saved in the existing format no matter what the user selects. &lt;/p&gt;
&lt;p&gt;For instance, if your code sets out the following:&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;fname = Application.GetSaveAsFilename(InitialFileName:= activeWorkbook.Name, filefilter:= _&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;st0&quot;&gt;&quot; Excel Macro Free Workbook (*.xlsx), *.xlsx,&quot;&lt;/span&gt; &amp; _&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;st0&quot;&gt;&quot; Excel Macro Enabled Workbook (*.xlsm), *.xlsm,&quot;&lt;/span&gt; &amp; _&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;st0&quot;&gt;&quot; Excel 2000-2003 Workbook (*.xls), *.xls,&quot;&lt;/span&gt; &amp; _&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;st0&quot;&gt;&quot; Excel Binary Workbook (*.xlsb), *.xlsb&quot;&lt;/span&gt;, _&lt;br&gt;
&#160; &#160; &#160; &#160; FilterIndex:=2, Title:=&lt;span class=&quot;st0&quot;&gt;&quot;Save as&quot;&lt;/span&gt;)&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;...and your file is currently in &lt;b&gt;.xlsm &lt;/b&gt; format with the name of &lt;b&gt;test&lt;/b&gt; then you will get a filename of &lt;b&gt;test&lt;/b&gt;. But if your file is currently in &lt;b&gt;.xls&lt;/b&gt; format then you will get a filename of &lt;b&gt;&quot;test.xls&quot;&lt;/b&gt; (including the quotation marks and file extension) and even if you select the &quot;Excel macro enabled workbook&quot; option from the &quot;Save as type&quot; dropdown it will still be saved as an .xls.&lt;/p&gt;
&lt;p&gt;To get around this, I amended the above to this:&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160;Need to get excel to pre-set the filterindex setting to match the existing file, rather than have a hard-coded value.&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160;For some reason if the current extension doesn&#039;t match the default filterindex setting then&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160;the activeworkbook.name is returned in quotation marks, and whatever the user selects from the filterindex&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160;dropdown has no effect unless those quotation marks are removed.&lt;br&gt;
&lt;/span&gt; &#160; &#160; &#160; &#160;&lt;span class=&quot;kw1&quot;&gt;Select&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Case&lt;/span&gt; LCase(Right(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - InStrRev(ActiveWorkbook.Name, &lt;span class=&quot;st0&quot;&gt;&quot;.&quot;&lt;/span&gt;, , 1)))&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Case&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;xlsx&quot;&lt;/span&gt;: FilterIndexValue = 1&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Case&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;xlsm&quot;&lt;/span&gt;: FilterIndexValue = 2&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Case&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;xls&quot;&lt;/span&gt;: FilterIndexValue = 3&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Case&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;xlsb&quot;&lt;/span&gt;: FilterIndexValue = 4&lt;br&gt;
&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Case&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Else&lt;/span&gt;: FilterIndexValue = 3 &lt;span class=&quot;co1&quot;&gt;&#039;make this the default in the event that we get no match.&lt;br&gt;
&lt;/span&gt; &#160; &#160; &#160; &#160;&lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Select&lt;/span&gt;&lt;br&gt;
&#160; &lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;co1&quot;&gt;&#039;Give the user the choice to save in 2000-2003 format or in one of the&lt;br&gt;
&lt;/span&gt; &#160; &#160; &#160; &#160;&lt;span class=&quot;co1&quot;&gt;&#039;new formats. Use the &quot;Save as type&quot; dropdown to make a choice,Default =&lt;br&gt;
&lt;/span&gt; &#160; &#160; &#160; &#160;&lt;span class=&quot;co1&quot;&gt;&#039;Excel Macro Enabled Workbook. You can add or remove formats to/from the list&lt;br&gt;
&lt;/span&gt; &#160; &#160; &#160; &#160;&lt;br&gt;
&#160; &#160; &#160; &#160; fname = Application.GetSaveAsFilename(InitialFileName:=ActiveWorkbook.Name, filefilter:= _&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;st0&quot;&gt;&quot; Excel Macro Free Workbook (*.xlsx), *.xlsx,&quot;&lt;/span&gt; &amp; _&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;st0&quot;&gt;&quot; Excel Macro Enabled Workbook (*.xlsm), *.xlsm,&quot;&lt;/span&gt; &amp; _&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;st0&quot;&gt;&quot; Excel 2000-2003 Workbook (*.xls), *.xls,&quot;&lt;/span&gt; &amp; _&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;st0&quot;&gt;&quot; Excel Binary Workbook (*.xlsb), *.xlsb&quot;&lt;/span&gt;, _&lt;br&gt;
&#160; &#160; &#160; &#160; FilterIndex:=FilterIndexValue, Title:=&lt;span class=&quot;st0&quot;&gt;&quot;This example copies the ActiveSheet to a new workbook&quot;&lt;/span&gt;)&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>Interesting&#8230;I amended this code so that instead of the filename being blank, it returns the ActiveWorkbook.Name. However, it turns out that if the filterindex setting does not <em>exactly</em> match the filetype as the workbook currently has, then the ActiveWorkbook.Name will be enclosed in quotation marks, and if a user then selects another filetype from the &#8216;Save as type&#8217; dropdown this has no effect unless/until they have removed those quotation marks&#8230;that is, the file is saved in the existing format no matter what the user selects. </p>
<p>For instance, if your code sets out the following:</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer">fname = Application.GetSaveAsFilename(InitialFileName:= activeWorkbook.Name, filefilter:= _<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8221; Excel Macro Free Workbook (*.xlsx), *.xlsx,&#8221;</span> &amp; _<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8221; Excel Macro Enabled Workbook (*.xlsm), *.xlsm,&#8221;</span> &amp; _<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8221; Excel 2000-2003 Workbook (*.xls), *.xls,&#8221;</span> &amp; _<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8221; Excel Binary Workbook (*.xlsb), *.xlsb&#8221;</span>, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; FilterIndex:=2, Title:=<span class="st0">&#8220;Save as&#8221;</span>)</div>
</div>
<p>&#8230;and your file is currently in <b>.xlsm </b> format with the name of <b>test</b> then you will get a filename of <b>test</b>. But if your file is currently in <b>.xls</b> format then you will get a filename of <b>&#8220;test.xls&#8221;</b> (including the quotation marks and file extension) and even if you select the &#8220;Excel macro enabled workbook&#8221; option from the &#8220;Save as type&#8221; dropdown it will still be saved as an .xls.</p>
<p>To get around this, I amended the above to this:</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp;Need to get excel to pre-set the filterindex setting to match the existing file, rather than have a hard-coded value.<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp;For some reason if the current extension doesn&#8217;t match the default filterindex setting then<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp;the activeworkbook.name is returned in quotation marks, and whatever the user selects from the filterindex<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp;dropdown has no effect unless those quotation marks are removed.<br />
</span> &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">Select</span> <span class="kw1">Case</span> LCase(Right(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) &#8211; InStrRev(ActiveWorkbook.Name, <span class="st0">&#8220;.&#8221;</span>, , 1)))<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Case</span> <span class="st0">&#8220;xlsx&#8221;</span>: FilterIndexValue = 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Case</span> <span class="st0">&#8220;xlsm&#8221;</span>: FilterIndexValue = 2<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Case</span> <span class="st0">&#8220;xls&#8221;</span>: FilterIndexValue = 3<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Case</span> <span class="st0">&#8220;xlsb&#8221;</span>: FilterIndexValue = 4</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Case</span> <span class="kw1">Else</span>: FilterIndexValue = 3 <span class="co1">&#8216;make this the default in the event that we get no match.<br />
</span> &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">End</span> <span class="kw1">Select</span><br />
&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">&#8216;Give the user the choice to save in 2000-2003 format or in one of the<br />
</span> &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">&#8216;new formats. Use the &#8220;Save as type&#8221; dropdown to make a choice,Default =<br />
</span> &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">&#8216;Excel Macro Enabled Workbook. You can add or remove formats to/from the list<br />
</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; fname = Application.GetSaveAsFilename(InitialFileName:=ActiveWorkbook.Name, filefilter:= _<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8221; Excel Macro Free Workbook (*.xlsx), *.xlsx,&#8221;</span> &amp; _<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8221; Excel Macro Enabled Workbook (*.xlsm), *.xlsm,&#8221;</span> &amp; _<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8221; Excel 2000-2003 Workbook (*.xls), *.xls,&#8221;</span> &amp; _<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8221; Excel Binary Workbook (*.xlsb), *.xlsb&#8221;</span>, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; FilterIndex:=FilterIndexValue, Title:=<span class="st0">&#8220;This example copies the ActiveSheet to a new workbook&#8221;</span>)</div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Weir</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/10/getsaveasfilename/#comment-54972</link>
		<dc:creator>Jeff Weir</dc:creator>
		<pubDate>Mon, 29 Nov 2010 10:43:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=618#comment-54972</guid>
		<description>&lt;p&gt;Thanks Patrick...this code works just fine.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks Patrick&#8230;this code works just fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick O'Beirne</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/10/getsaveasfilename/#comment-54916</link>
		<dc:creator>Patrick O'Beirne</dc:creator>
		<pubDate>Sun, 28 Nov 2010 14:56:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=618#comment-54916</guid>
		<description>&lt;p&gt;See:&lt;br&gt;
&lt;a href=&quot;http://www.rondebruin.nl/saveas.htm&quot; rel=&quot;nofollow&quot;&gt;http://www.rondebruin.nl/saveas.htm&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&#039;In Excel 2007, SaveAs requires you to provide both the FileFormat parameter and the correct file extension.&lt;br&gt;
&#039; pass three params, first two changed by ref&lt;br&gt;
Sub GetSaveAsFileFormat(ByRef sFileName As String, ByRef lFileFormatValue As Long, ByVal sTitle As String)&lt;br&gt;
If Val(Application.Version) &lt; 12 Then&lt;br&gt;
   lFileFormatValue = -4143&lt;br&gt;
   &#039;Only choice in the &quot;Save as type&quot; dropdown is Excel files(xls)&lt;br&gt;
   &#039;because the Excel version is 2000-2003&lt;br&gt;
   sFileName = Application.GetSaveAsFilename(InitialFileName:=sFileName, _&lt;br&gt;
      FileFilter:=&quot;Excel Files (*.xls), *.xls&quot;, _&lt;br&gt;
      Title:=sTitle)&lt;br&gt;
Else&lt;br&gt;
   sFileName = Application.GetSaveAsFilename(InitialFileName:=sFileName, FileFilter:= _&lt;br&gt;
      &quot; Excel Macro Free Workbook (*.xlsx), *.xlsx,&quot; &amp; _&lt;br&gt;
      &quot; Excel Macro Enabled Workbook (*.xlsm), *.xlsm,&quot; &amp; _&lt;br&gt;
      &quot; Excel 2000-2003 Workbook (*.xls), *.xls,&quot; &amp; _&lt;br&gt;
      &quot; Excel Binary Workbook (*.xlsb), *.xlsb&quot;, _&lt;br&gt;
      FilterIndex:=1, Title:=sTitle)&lt;br&gt;
End If&lt;br&gt;
If StrComp(sFileName, &quot;False&quot;, vbTextCompare)  0 Then&lt;br&gt;
   &#039; get the file format the user asked for from the file name&lt;br&gt;
   lFileFormatValue = FileFormatValue(sFileName)&lt;br&gt;
End If&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;Function FileFormatValue(sFileName As String) As Long&lt;br&gt;
If Val(Application.Version) &lt; 12 Then&lt;br&gt;
   FileFormatValue = -4143 &#039; &quot; Excel 2000-2003 Workbook (*.xls), *.xls,&quot;&lt;br&gt;
   &#039;Only choice in the &quot;Save as type&quot; dropdown is Excel files(xls)&lt;br&gt;
Else&lt;br&gt;
   &#039;Find the correct FileFormat that match the choice in the &quot;Save as type&quot; list&lt;br&gt;
   Select Case FileExtension(sFileName)&lt;br&gt;
   Case &quot;xls&quot;: FileFormatValue = 56    &#039;xlExcel8 &quot; Excel 2000-2003 Workbook (*.xls), *.xls,&quot;&lt;br&gt;
   Case &quot;xlsb&quot;: FileFormatValue = 50   &#039;xlExcel12 &quot; Excel Binary Workbook (*.xlsb), *.xlsb&quot;,&lt;br&gt;
   Case &quot;xlsx&quot;: FileFormatValue = 51   &#039;xlOpenXMLWorkbook &quot; Excel Macro Free Workbook (*.xlsx), *.xlsx,&quot;&lt;br&gt;
   Case &quot;xlsm&quot;: FileFormatValue = 52   &#039;xlOpenXMLWorkbookMacroEnabled &quot; Excel Macro Enabled Workbook (*.xlsm), *.xlsm,&quot;&lt;br&gt;
   Case &quot;xltm&quot;: FileFormatValue = 53   &#039;xlOpenXMLTemplateMacroEnabled  Open XML Template Macro Enabled&lt;br&gt;
   Case &quot;xltx&quot;: FileFormatValue = 54   &#039;xlOpenXMLTemplate Open XML Template&lt;br&gt;
   Case &quot;xlam&quot;: FileFormatValue = 55   &#039;xlOpenXMLAddIn Open XML Add-In&lt;br&gt;
   Case Else: FileFormatValue = 0      &#039; undefined, let the caller figure it out&lt;br&gt;
   &#039; 46 is XML spreadsheet&lt;br&gt;
   &#039; 60 is xlOpenDocumentSpreadsheet, .ODS?&lt;br&gt;
   End Select&lt;br&gt;
End If&lt;br&gt;
End Function&lt;/p&gt;
&lt;p&gt;&#039; return the default file extension for the given workbook&lt;br&gt;
&#039; which may be different from the actual extension which may be none if unsaved&lt;br&gt;
Function DefaultFileExtension(wb As Workbook) As String&lt;br&gt;
If Val(Application.Version) &lt; 12 Then&lt;br&gt;
   DefaultFileExtension = &quot;xls&quot; &#039; FileFormatValue = -4143&lt;br&gt;
ElseIf wb Is Nothing Then&lt;br&gt;
   DefaultFileExtension = &quot;xlsx&quot; &#039; Excel 2007&lt;br&gt;
Else&lt;br&gt;
   Select Case wb.FileFormat&lt;br&gt;
   Case 50: DefaultFileExtension = &quot;xlsb&quot;&lt;br&gt;
   Case 51: DefaultFileExtension = &quot;xlsx&quot;&lt;br&gt;
   Case 52: DefaultFileExtension = &quot;xlsm&quot;&lt;br&gt;
   Case 56: DefaultFileExtension = &quot;xls&quot;&lt;br&gt;
   Case Else: DefaultFileExtension = &quot;xlsx&quot; &#039; Excel 2007&lt;br&gt;
   End Select&lt;br&gt;
End If&lt;br&gt;
End Function&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>See:<br />
<a href="http://www.rondebruin.nl/saveas.htm" rel="nofollow">http://www.rondebruin.nl/saveas.htm</a></p>
<p>&#8216;In Excel 2007, SaveAs requires you to provide both the FileFormat parameter and the correct file extension.<br />
&#8216; pass three params, first two changed by ref<br />
Sub GetSaveAsFileFormat(ByRef sFileName As String, ByRef lFileFormatValue As Long, ByVal sTitle As String)<br />
If Val(Application.Version) &lt; 12 Then<br />
   lFileFormatValue = -4143<br />
   &#8216;Only choice in the &#8220;Save as type&#8221; dropdown is Excel files(xls)<br />
   &#8216;because the Excel version is 2000-2003<br />
   sFileName = Application.GetSaveAsFilename(InitialFileName:=sFileName, _<br />
      FileFilter:=&#8221;Excel Files (*.xls), *.xls&#8221;, _<br />
      Title:=sTitle)<br />
Else<br />
   sFileName = Application.GetSaveAsFilename(InitialFileName:=sFileName, FileFilter:= _<br />
      &#8221; Excel Macro Free Workbook (*.xlsx), *.xlsx,&#8221; &amp; _<br />
      &#8221; Excel Macro Enabled Workbook (*.xlsm), *.xlsm,&#8221; &amp; _<br />
      &#8221; Excel 2000-2003 Workbook (*.xls), *.xls,&#8221; &amp; _<br />
      &#8221; Excel Binary Workbook (*.xlsb), *.xlsb&#8221;, _<br />
      FilterIndex:=1, Title:=sTitle)<br />
End If<br />
If StrComp(sFileName, &#8220;False&#8221;, vbTextCompare)  0 Then<br />
   &#8216; get the file format the user asked for from the file name<br />
   lFileFormatValue = FileFormatValue(sFileName)<br />
End If<br />
End Sub</p>
<p>Function FileFormatValue(sFileName As String) As Long<br />
If Val(Application.Version) &lt; 12 Then<br />
   FileFormatValue = -4143 &#8216; &#8221; Excel 2000-2003 Workbook (*.xls), *.xls,&#8221;<br />
   &#8216;Only choice in the &#8220;Save as type&#8221; dropdown is Excel files(xls)<br />
Else<br />
   &#8216;Find the correct FileFormat that match the choice in the &#8220;Save as type&#8221; list<br />
   Select Case FileExtension(sFileName)<br />
   Case &#8220;xls&#8221;: FileFormatValue = 56    &#8216;xlExcel8 &#8221; Excel 2000-2003 Workbook (*.xls), *.xls,&#8221;<br />
   Case &#8220;xlsb&#8221;: FileFormatValue = 50   &#8216;xlExcel12 &#8221; Excel Binary Workbook (*.xlsb), *.xlsb&#8221;,<br />
   Case &#8220;xlsx&#8221;: FileFormatValue = 51   &#8216;xlOpenXMLWorkbook &#8221; Excel Macro Free Workbook (*.xlsx), *.xlsx,&#8221;<br />
   Case &#8220;xlsm&#8221;: FileFormatValue = 52   &#8216;xlOpenXMLWorkbookMacroEnabled &#8221; Excel Macro Enabled Workbook (*.xlsm), *.xlsm,&#8221;<br />
   Case &#8220;xltm&#8221;: FileFormatValue = 53   &#8216;xlOpenXMLTemplateMacroEnabled  Open XML Template Macro Enabled<br />
   Case &#8220;xltx&#8221;: FileFormatValue = 54   &#8216;xlOpenXMLTemplate Open XML Template<br />
   Case &#8220;xlam&#8221;: FileFormatValue = 55   &#8216;xlOpenXMLAddIn Open XML Add-In<br />
   Case Else: FileFormatValue = 0      &#8216; undefined, let the caller figure it out<br />
   &#8216; 46 is XML spreadsheet<br />
   &#8216; 60 is xlOpenDocumentSpreadsheet, .ODS?<br />
   End Select<br />
End If<br />
End Function</p>
<p>&#8216; return the default file extension for the given workbook<br />
&#8216; which may be different from the actual extension which may be none if unsaved<br />
Function DefaultFileExtension(wb As Workbook) As String<br />
If Val(Application.Version) &lt; 12 Then<br />
   DefaultFileExtension = &#8220;xls&#8221; &#8216; FileFormatValue = -4143<br />
ElseIf wb Is Nothing Then<br />
   DefaultFileExtension = &#8220;xlsx&#8221; &#8216; Excel 2007<br />
Else<br />
   Select Case wb.FileFormat<br />
   Case 50: DefaultFileExtension = &#8220;xlsb&#8221;<br />
   Case 51: DefaultFileExtension = &#8220;xlsx&#8221;<br />
   Case 52: DefaultFileExtension = &#8220;xlsm&#8221;<br />
   Case 56: DefaultFileExtension = &#8220;xls&#8221;<br />
   Case Else: DefaultFileExtension = &#8220;xlsx&#8221; &#8216; Excel 2007<br />
   End Select<br />
End If<br />
End Function</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeff weir</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/10/getsaveasfilename/#comment-54490</link>
		<dc:creator>jeff weir</dc:creator>
		<pubDate>Mon, 22 Nov 2010 23:30:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=618#comment-54490</guid>
		<description>&lt;p&gt;I was hoping to use the GetSaveAsFilename method so that I could get a macro to run AFTER the save that refreshes a pivotcache connection in the case that a workbook has been renamed. (I need to do this because the pivot is querying information within the workbook using SQL. If I don&#039;t update the connection after file rename, the sql query will be accessing the data in the previous version of the workbook, not the current version).&lt;/p&gt;
&lt;p&gt;Only problem is, the GetSaveAsFilename method doesn&#039;t return whatever filetype the user picks from the FileFilter list (although I&#039;ve only got one type listed in the below sub). So the user can&#039;t change the format...It saves in whatever format the excel workbook is curretly in(unless no format is specified...in which case my sub saves it in .xls format).&lt;/p&gt;
&lt;p&gt;I&#039;ve got two questions for the floor:&lt;br&gt;
1. Anyone got any good suggestion as to how I could allow users to change the filetype based on what they select with the GetSaveAsFilename dialogue? I&#039;m guessing this cant be done with this method, and I&#039;d instead have to create a dialogue box that returns both the filename and the file type. If so, can&#039;t say i really see the point of the GetSaveAsFilename method.&lt;br&gt;
2. If I just stick with current code, can it be written any smarter? I&#039;m very new to VBA, and keen to learn if I&#039;m doing anything unneccessary. &lt;/p&gt;
&lt;p&gt;Thanks for any suggestions.&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container text default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;text codecolorer&quot;&gt;Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)&lt;br&gt;
&lt;br&gt;
Dim FName As String&lt;br&gt;
&lt;br&gt;
If Not SaveAsUI Then Exit Sub&lt;br&gt;
Application.EnableEvents = False&lt;br&gt;
FName = Application.GetSaveAsFilename(, FileFilter:=&quot;Excel Workbook, *.xl*&quot;)&lt;br&gt;
&lt;br&gt;
If FName &lt;&gt; &quot;False&quot; Then&lt;br&gt;
&#160; &#160; If InStr(1, Right(FName, 4), &quot;xls&quot;) = 0 Then FName = FName &amp; &quot;.xls&quot;&lt;br&gt;
&#160; &#160; ThisWorkbook.SaveAs Filename:=FName, FileFormat:=56&lt;br&gt;
&#160; &#160; End If&lt;br&gt;
Application.EnableEvents = True&lt;br&gt;
Cancel = True&lt;br&gt;
&lt;br&gt;
Call Update_Pivot_Connection&lt;br&gt;
&lt;br&gt;
End Sub&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>I was hoping to use the GetSaveAsFilename method so that I could get a macro to run AFTER the save that refreshes a pivotcache connection in the case that a workbook has been renamed. (I need to do this because the pivot is querying information within the workbook using SQL. If I don&#8217;t update the connection after file rename, the sql query will be accessing the data in the previous version of the workbook, not the current version).</p>
<p>Only problem is, the GetSaveAsFilename method doesn&#8217;t return whatever filetype the user picks from the FileFilter list (although I&#8217;ve only got one type listed in the below sub). So the user can&#8217;t change the format&#8230;It saves in whatever format the excel workbook is curretly in(unless no format is specified&#8230;in which case my sub saves it in .xls format).</p>
<p>I&#8217;ve got two questions for the floor:<br />
1. Anyone got any good suggestion as to how I could allow users to change the filetype based on what they select with the GetSaveAsFilename dialogue? I&#8217;m guessing this cant be done with this method, and I&#8217;d instead have to create a dialogue box that returns both the filename and the file type. If so, can&#8217;t say i really see the point of the GetSaveAsFilename method.<br />
2. If I just stick with current code, can it be written any smarter? I&#8217;m very new to VBA, and keen to learn if I&#8217;m doing anything unneccessary. </p>
<p>Thanks for any suggestions.</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container text default">
<div style="white-space: nowrap;" class="text codecolorer">Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)</p>
<p>Dim FName As String</p>
<p>If Not SaveAsUI Then Exit Sub<br />
Application.EnableEvents = False<br />
FName = Application.GetSaveAsFilename(, FileFilter:=&#8221;Excel Workbook, *.xl*&#8221;)</p>
<p>If FName &lt;&gt; &#8220;False&#8221; Then<br />
&nbsp; &nbsp; If InStr(1, Right(FName, 4), &#8220;xls&#8221;) = 0 Then FName = FName &amp; &#8220;.xls&#8221;<br />
&nbsp; &nbsp; ThisWorkbook.SaveAs Filename:=FName, FileFormat:=56<br />
&nbsp; &nbsp; End If<br />
Application.EnableEvents = True<br />
Cancel = True</p>
<p>Call Update_Pivot_Connection</p>
<p>End Sub</p></div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathon</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/10/getsaveasfilename/#comment-48335</link>
		<dc:creator>Jonathon</dc:creator>
		<pubDate>Mon, 26 Jul 2010 22:59:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=618#comment-48335</guid>
		<description>&lt;p&gt;Thanks, Wes.  You saved me at least an hour of googling!!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks, Wes.  You saved me at least an hour of googling!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wes Groleau</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/10/getsaveasfilename/#comment-38742</link>
		<dc:creator>Wes Groleau</dc:creator>
		<pubDate>Tue, 31 Mar 2009 17:35:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=618#comment-38742</guid>
		<description>&lt;p&gt;FileFilter does not work on Macleve it out.&lt;/p&gt;
&lt;p&gt;And on Windows, it does not work the way the help claims.&lt;/p&gt;
&lt;p&gt;The following works on Windows, but it took me at least an hour of googling and experimenting:&lt;/p&gt;
&lt;p&gt;        Out_File = Application.GetSaveAsFilename _&lt;br&gt;
                    (InitialFileName:=&quot;EDIT_THIS&quot;, _&lt;br&gt;
                     Title:=&quot;Select output file name (Cancel means NONE)&quot;, _&lt;br&gt;
                     FileFilter:=&quot;GEDCOM (*.ged), *.ged, Text (*.txt), *.txt, Any (*.*), *.*&quot;)&lt;/p&gt;
&lt;p&gt;For Mac, omit the FileFilter param.  If you want both, try one of these:&lt;/p&gt;
&lt;p&gt;    If Left(Application.OperatingSystem, 3) = &quot;Mac&quot; Then&lt;br&gt;
    If Application.OperatingSystem  Like &quot;Mac*&quot; Then&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>FileFilter does not work on Macleve it out.</p>
<p>And on Windows, it does not work the way the help claims.</p>
<p>The following works on Windows, but it took me at least an hour of googling and experimenting:</p>
<p>        Out_File = Application.GetSaveAsFilename _<br />
                    (InitialFileName:=&#8221;EDIT_THIS&#8221;, _<br />
                     Title:=&#8221;Select output file name (Cancel means NONE)&#8221;, _<br />
                     FileFilter:=&#8221;GEDCOM (*.ged), *.ged, Text (*.txt), *.txt, Any (*.*), *.*&#8221;)</p>
<p>For Mac, omit the FileFilter param.  If you want both, try one of these:</p>
<p>    If Left(Application.OperatingSystem, 3) = &#8220;Mac&#8221; Then<br />
    If Application.OperatingSystem  Like &#8220;Mac*&#8221; Then</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/10/getsaveasfilename/#comment-31394</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Thu, 20 Mar 2008 19:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=618#comment-31394</guid>
		<description>&lt;p&gt;Hi John,&lt;/p&gt;
&lt;p&gt;Thanks for the advice, but it&#039;s still not working for me.  I think (hope) I&#039;m just doing something dumb.  Per your advice I&#039;ve removed the underscores and made the entire thing one long line of code:&lt;/p&gt;
&lt;p&gt;DestFile = Application.GetSaveAsFilename( InitialFileName:=&quot;MyTabDelim.txt&quot;, FileFilter:=&quot;Text files, *.txt&quot;, Title:=&quot;Save Tab Delimited File&quot;)&lt;/p&gt;
&lt;p&gt;But I get a compile error that says &quot;Expected: list separator or )&quot; and the word &quot;files&quot; of &#039;FileFilter:=&quot;Text files,&#039; is highlighted.&lt;/p&gt;
&lt;p&gt;This also happens if I leave the underscores in place and hit &quot;enter&quot; after each one:&lt;/p&gt;
&lt;p&gt;DestFile = Application.GetSaveAsFilename( _&lt;br&gt;
InitialFileName:=&quot;MyTabDelim.txt&quot;, _&lt;br&gt;
FileFilter:=&quot;Text files, *.txt&quot;, _&lt;br&gt;
Title:=&quot;Save Tab Delimited File&quot;)&lt;/p&gt;
&lt;p&gt;Again, any help is greatly appreciated!  Thanks for the help so far!&lt;/p&gt;
&lt;p&gt;-Ben&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi John,</p>
<p>Thanks for the advice, but it&#8217;s still not working for me.  I think (hope) I&#8217;m just doing something dumb.  Per your advice I&#8217;ve removed the underscores and made the entire thing one long line of code:</p>
<p>DestFile = Application.GetSaveAsFilename( InitialFileName:=&#8221;MyTabDelim.txt&#8221;, FileFilter:=&#8221;Text files, *.txt&#8221;, Title:=&#8221;Save Tab Delimited File&#8221;)</p>
<p>But I get a compile error that says &#8220;Expected: list separator or )&#8221; and the word &#8220;files&#8221; of &#8216;FileFilter:=&#8221;Text files,&#8217; is highlighted.</p>
<p>This also happens if I leave the underscores in place and hit &#8220;enter&#8221; after each one:</p>
<p>DestFile = Application.GetSaveAsFilename( _<br />
InitialFileName:=&#8221;MyTabDelim.txt&#8221;, _<br />
FileFilter:=&#8221;Text files, *.txt&#8221;, _<br />
Title:=&#8221;Save Tab Delimited File&#8221;)</p>
<p>Again, any help is greatly appreciated!  Thanks for the help so far!</p>
<p>-Ben</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/10/getsaveasfilename/#comment-31324</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Mon, 17 Mar 2008 19:29:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=618#comment-31324</guid>
		<description>&lt;p&gt;Only tangentially related, but it&#039;s extremely annoying that Excel saves both CSV and Tab-delimited value files in a way which Access cannot import by default. That is, Excel throws quotes in to screw up Access whenever there&#039;s a space in a value (even for tab-delimited files, where it makes no sense whatsoever to quote values with spaces in them). Leave it to Microsoft...&lt;/p&gt;
&lt;p&gt;I ended up having to write my own routine to write a proper tab-delimited file that Access can import without problems.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Only tangentially related, but it&#8217;s extremely annoying that Excel saves both CSV and Tab-delimited value files in a way which Access cannot import by default. That is, Excel throws quotes in to screw up Access whenever there&#8217;s a space in a value (even for tab-delimited files, where it makes no sense whatsoever to quote values with spaces in them). Leave it to Microsoft&#8230;</p>
<p>I ended up having to write my own routine to write a proper tab-delimited file that Access can import without problems.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Peltier</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/10/getsaveasfilename/#comment-31320</link>
		<dc:creator>Jon Peltier</dc:creator>
		<pubDate>Mon, 17 Mar 2008 12:25:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=618#comment-31320</guid>
		<description>&lt;p&gt;Space + Underscore means this line continued on the next line. Somehow that line didn&#039;t wrap in the source you copied. Take out the offending underscore character, or put thee cursor right after it and press Enter.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Space + Underscore means this line continued on the next line. Somehow that line didn&#8217;t wrap in the source you copied. Take out the offending underscore character, or put thee cursor right after it and press Enter.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

