{"id":105,"date":"2011-01-13T14:47:06","date_gmt":"2011-01-13T13:47:06","guid":{"rendered":"http:\/\/mariaevert.dk\/vba\/?p=105"},"modified":"2011-01-13T15:31:07","modified_gmt":"2011-01-13T14:31:07","slug":"vba-toggle-between-open-excel-files","status":"publish","type":"post","link":"https:\/\/mariaevert.dk\/vba\/?p=105","title":{"rendered":"VBA &#8211; Toggle Between Open Excel Files"},"content":{"rendered":"<p>There is often need of working in two worksheets at a time &#8211; for example when you want to loop throigh the files in a folder, and copy data from each of them into a new file, thus gathering different data into one worksheet. <\/p>\n<p>Here are some small code snippets that are needed to work with multiple worksheets at a time. <\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n\r\n'Get the name of the currently active file. You'll need this when \r\n'toggelinig between two files, and you want to open the old file\r\n'where the data is assembled\r\n\r\nDim OrginialFile\r\nOriginalFile = Application.ActiveWorkbook.Name\r\n\r\n\r\n\r\n'Open new file\r\nDim MyFile\r\nMyFile = &quot;C:Maria\\Myfolder\\Myfile.xls&quot;\r\n\r\n Workbooks.Open FileName:=MyFile\r\n\r\n\r\n'Close a file\r\nDim MyNewFile\r\nMyNewFile = &quot;MyWonderfulFile.xls&quot;\r\n'Unable ScreenUpdating and DisoplayAlerts, so teh user isn't asked if he want tosave the changes\r\n  Application.ScreenUpdating = False\r\n  Application.DisplayAlerts = False\r\n             Windows(MyNewFile).Close\r\n  Application.ScreenUpdating = true\r\n   Application.DisplayAlerts = true\r\n\r\n'Toggle between open files. \r\nDim AnotherOpenFile\r\nAnotherOpenFile = &quot;MyWounderfullFile.xls&quot;\r\n\r\nWindows(AnotherOpenFile ).Activate\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>There is often need of working in two worksheets at a time &#8211; for example when you want to loop throigh the files in a folder, and copy data from each of them into a new file, thus gathering different data into one worksheet. Here are some small code snippets that are needed to work [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/posts\/105"}],"collection":[{"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=105"}],"version-history":[{"count":5,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/posts\/105\/revisions"}],"predecessor-version":[{"id":108,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/posts\/105\/revisions\/108"}],"wp:attachment":[{"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}