{"id":108,"date":"2015-09-10T10:23:40","date_gmt":"2015-09-10T10:23:40","guid":{"rendered":"http:\/\/99excel.com\/?p=108"},"modified":"2021-05-14T16:09:21","modified_gmt":"2021-05-14T16:09:21","slug":"vba-code-for-move-file-to-other-folder","status":"publish","type":"post","link":"https:\/\/99excel.com\/home\/vba-code-for-move-file-to-other-folder\/","title":{"rendered":"VBA code for move file to other folder"},"content":{"rendered":"<p>Sub CheckIfFileExists()<\/p>\n<p>Dim LRow As Integer<br \/>\nDim LPath As String<br \/>\nDim LExtension As String<\/p>\n<p>Dim LContinue As Boolean<br \/>\nDim MPath As Integer<br \/>\nDim FNAme As String<\/p>\n<p>Dim sourceFile As String<br \/>\nDim targetFile As String<\/p>\n<p>Dim fso As Object<\/p>\n<p>LContinue = True<br \/>\nLRow = 2<br \/>\nMPath = 2<br \/>\nLPath = &#8220;C:New Folder&#8221;<br \/>\nLExtension = &#8220;.pdf&#8221;<\/p>\n<p>While LContinue<\/p>\n<p>If Len(Range(&#8220;A&#8221; &amp; CStr(LRow)).Value) = 0 Then<br \/>\nLContinue = False<\/p>\n<p>Else<\/p>\n<p>aa = &#8220;C:New Folder&#8221;<\/p>\n<p>Set fso = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<\/p>\n<p>bb = &#8220;C:New Folder&#8221;<\/p>\n<p>Set fs = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<\/p>\n<p>bb = bb &amp; &#8220;&#8221; &amp; Range(&#8220;A&#8221; &amp; CStr(MPath)).Value<br \/>\nbb = bb &amp; &#8220;.PDF&#8221;<\/p>\n<p>If fs.FileExists(bb) = True Then<\/p>\n<p>Range(&#8220;B&#8221; &amp; CStr(LRow)).Value = &#8220;Yes&#8221;<\/p>\n<p>FNAme = Range(&#8220;C&#8221; &amp; CStr(MPath)).Value<br \/>\naa = aa &amp; &#8220;&#8221; &amp; FNAme<\/p>\n<p>If fs.FolderExists(aa) = False Then<br \/>\nfs.createfolder aa<\/p>\n<p>End If<\/p>\n<p>aa = aa &amp; &#8220;&#8221;<br \/>\nfso.MoveFile bb, aa<\/p>\n<p>End If<br \/>\nEnd If<\/p>\n<p>Set fs = Nothing<br \/>\nSet fso = Nothing<\/p>\n<p>LRow = LRow + 1<br \/>\nMPath = MPath + 1<br \/>\nWend<\/p>\n<p>End Sub<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sub CheckIfFileExists() Dim LRow As Integer Dim LPath As String Dim LExtension As String Dim LContinue As Boolean Dim MPath As Integer Dim FNAme As String Dim sourceFile As String Dim targetFile As String Dim fso As Object LContinue = True LRow = 2 MPath = 2 LPath = &#8220;C:New Folder&#8221; LExtension = &#8220;.pdf&#8221; While &#8230; <a title=\"VBA code for move file to other folder\" class=\"read-more\" href=\"https:\/\/99excel.com\/home\/vba-code-for-move-file-to-other-folder\/\" aria-label=\"More on VBA code for move file to other folder\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-108","post","type-post","status-publish","format-standard","hentry"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/99excel.com\/home\/wp-json\/wp\/v2\/posts\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/99excel.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/99excel.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/99excel.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/99excel.com\/home\/wp-json\/wp\/v2\/comments?post=108"}],"version-history":[{"count":1,"href":"https:\/\/99excel.com\/home\/wp-json\/wp\/v2\/posts\/108\/revisions"}],"predecessor-version":[{"id":869,"href":"https:\/\/99excel.com\/home\/wp-json\/wp\/v2\/posts\/108\/revisions\/869"}],"wp:attachment":[{"href":"https:\/\/99excel.com\/home\/wp-json\/wp\/v2\/media?parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/99excel.com\/home\/wp-json\/wp\/v2\/categories?post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/99excel.com\/home\/wp-json\/wp\/v2\/tags?post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}