{"id":3285,"date":"2018-10-29T09:09:52","date_gmt":"2018-10-29T09:09:52","guid":{"rendered":"http:\/\/officetuts.net\/excel\/?p=3285"},"modified":"2024-03-30T00:12:41","modified_gmt":"2024-03-30T00:12:41","slug":"vba-save-as","status":"publish","type":"post","link":"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/","title":{"rendered":"VBA Save as"},"content":{"rendered":"\n

In order to save a workbook in VBA, use Alt + F11<\/strong> and enter the following code.<\/p>\n\n\n\n

Sub SaveWorkbook()\n    ActiveWorkbook.Save\nEnd Sub<\/pre>\n\n\n\n

This procedure will save the file in the default location. If the file wasn\u2019t saved<\/a> yet, the new file is created, otherwise, it overwrites the old file.<\/p>\n\n\n\n

Save the file in the specified location<\/h2>\n\n\n\n

You can specify the name of the file you want to write.<\/p>\n\n\n\n

Sub SaveWorkbook()\n    Dim myFile As String\n    myFile = \"ExcelFile\"  \n\n    ActiveWorkbook.SaveAs Filename:=myFile, FileFormat:=xlOpenXMLWorkbook \u2018or 51\nEnd Sub<\/pre>\n\n\n\n

In the following code, I used xlOpenXMLWorkbook<\/strong> to save a standard Open XML Workbook (xlsx)<\/strong>.<\/p>\n\n\n\n

The other popular formats are:<\/p>\n\n\n\n

xlsm<\/strong> (Open XML Workbook Macro Enabled) \u2013 xlOpenXMLWorkbookMacroEnabled<\/strong> or 52<\/strong><\/p>\n\n\n\n

xlsb<\/strong> (Excel Binary Workbook) – xlExcel12<\/strong> or 50<\/strong><\/p>\n\n\n\n

csv<\/strong> \u2013 (CSV) \u2013 xlCSV<\/strong> or 6<\/strong><\/p>\n\n\n\n

If you want to save your file using a different format, you can use one of the following parameters (https:\/\/docs.microsoft.com\/en-us\/office\/vba\/api\/excel.xlfileformat).<\/p>\n\n\n\n

Save with a dialog box<\/h2>\n\n\n\n

So far we were saving a file<\/a> using a variable name. This code will ask you for a name for your file.<\/p>\n\n\n\n

Sub SaveWorkbook()\n    Dim myFile As Variant\n    Dim fileTypes As String   \n\n    fileTypes = \"Open XML Workbook (*.xlsx), *.xlsx, CSV (*.csv), *.csv\"   \n\n    myDialogBox = Application.GetSaveAsFilename(fileFilter:=fileTypes)   \n\n    If myDialogBox <> False Then\n        ActiveWorkbook.SaveAs Filename:=myDialogBox\n    End If\nEnd Sub<\/pre>\n\n\n\n

In the code, you can see a string called fileTypes<\/strong>. This is where you add file types. In this example, you can choose between xlsx and csv.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

You can add multiple other formats<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"

In order to save a workbook in VBA, use Alt + F11 and enter the following code. Sub SaveWorkbook()     ActiveWorkbook.Save End Sub…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[190],"yoast_head":"\nVBA Save as<\/title>\n<meta name=\"description\" content=\"Learn how to save an Excel workbook in VBA using Alt + F11, default location or specified location with code examples. #ExcelTips #VBAprogramming.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"VBA Save as\" \/>\n<meta property=\"og:description\" content=\"Learn how to save an Excel workbook in VBA using Alt + F11, default location or specified location with code examples. #ExcelTips #VBAprogramming.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-10-29T09:09:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-30T00:12:41+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/dialog-box-file-types.png\" \/>\n<meta name=\"author\" content=\"Tomasz Decker\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tomasz Decker\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/\"},\"author\":{\"name\":\"Tomasz Decker\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"headline\":\"VBA Save as\",\"datePublished\":\"2018-10-29T09:09:52+00:00\",\"dateModified\":\"2024-03-30T00:12:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/\"},\"wordCount\":194,\"publisher\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/dialog-box-file-types.png\",\"keywords\":[\"pinterest\"],\"articleSection\":[\"vba\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/\",\"url\":\"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/\",\"name\":\"VBA Save as\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/dialog-box-file-types.png\",\"datePublished\":\"2018-10-29T09:09:52+00:00\",\"dateModified\":\"2024-03-30T00:12:41+00:00\",\"description\":\"Learn how to save an Excel workbook in VBA using Alt + F11, default location or specified location with code examples. #ExcelTips #VBAprogramming.\",\"breadcrumb\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/#primaryimage\",\"url\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/dialog-box-file-types.png\",\"contentUrl\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/dialog-box-file-types.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/officetuts.net\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"VBA Save as\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/officetuts.net\/excel\/#website\",\"url\":\"https:\/\/officetuts.net\/excel\/\",\"name\":\"\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/officetuts.net\/excel\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\",\"name\":\"Tomasz Decker\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g\",\"caption\":\"Tomasz Decker\"},\"logo\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/\"},\"description\":\"Spreadsheet and Python enthusiast.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"VBA Save as","description":"Learn how to save an Excel workbook in VBA using Alt + F11, default location or specified location with code examples. #ExcelTips #VBAprogramming.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/","og_locale":"en_US","og_type":"article","og_title":"VBA Save as","og_description":"Learn how to save an Excel workbook in VBA using Alt + F11, default location or specified location with code examples. #ExcelTips #VBAprogramming.","og_url":"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/","article_published_time":"2018-10-29T09:09:52+00:00","article_modified_time":"2024-03-30T00:12:41+00:00","og_image":[{"url":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/dialog-box-file-types.png"}],"author":"Tomasz Decker","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Tomasz Decker","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/#article","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/"},"author":{"name":"Tomasz Decker","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"headline":"VBA Save as","datePublished":"2018-10-29T09:09:52+00:00","dateModified":"2024-03-30T00:12:41+00:00","mainEntityOfPage":{"@id":"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/"},"wordCount":194,"publisher":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"image":{"@id":"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/#primaryimage"},"thumbnailUrl":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/dialog-box-file-types.png","keywords":["pinterest"],"articleSection":["vba"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/","url":"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/","name":"VBA Save as","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/#website"},"primaryImageOfPage":{"@id":"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/#primaryimage"},"image":{"@id":"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/#primaryimage"},"thumbnailUrl":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/dialog-box-file-types.png","datePublished":"2018-10-29T09:09:52+00:00","dateModified":"2024-03-30T00:12:41+00:00","description":"Learn how to save an Excel workbook in VBA using Alt + F11, default location or specified location with code examples. #ExcelTips #VBAprogramming.","breadcrumb":{"@id":"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/#primaryimage","url":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/dialog-box-file-types.png","contentUrl":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/dialog-box-file-types.png"},{"@type":"BreadcrumbList","@id":"https:\/\/officetuts.net\/excel\/vba\/vba-save-as\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/officetuts.net\/excel\/"},{"@type":"ListItem","position":2,"name":"VBA Save as"}]},{"@type":"WebSite","@id":"https:\/\/officetuts.net\/excel\/#website","url":"https:\/\/officetuts.net\/excel\/","name":"","description":"","publisher":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/officetuts.net\/excel\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42","name":"Tomasz Decker","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g","caption":"Tomasz Decker"},"logo":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/"},"description":"Spreadsheet and Python enthusiast."}]}},"_links":{"self":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/3285"}],"collection":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/comments?post=3285"}],"version-history":[{"count":6,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/3285\/revisions"}],"predecessor-version":[{"id":12940,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/3285\/revisions\/12940"}],"wp:attachment":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/media?parent=3285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/categories?post=3285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/tags?post=3285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}