VBA CopyFolder copying wrong folderSending formatted Lotus Notes rich text email from Excel VBAIs there a way to crack the password on an Excel VBA Project?How to return a result from a VBA functionLoop through files in a folder using VBA?How to avoid using Select in Excel VBACopy Excel cells, evaluate content, and copy a file looping over the cell contents as filenameCopy data from worksheet to html file to mailMkDir not accepting variable argument (EXCEL-VBA)how to convert a column of text with html tags to formatted text in vba in excelVBA Copy Data goes wrong

Are gliders susceptible to bird strikes?

Do the 26 richest billionaires own as much wealth as the poorest 3.8 billion people?

Sacrifice blocking creature before damage is dealt no longer working (MtG Arena)?

What verb for taking advantage fits in "I don't want to ________ on the friendship"?

Will writing actual numbers instead of writing them with letters affect readership?

Sharing referee/AE report online to point out a grievous error in refereeing

How do we separate rules of logic from non-logical constraints?

Is there a legal way for US presidents to extend their terms beyond two terms of four years?

Could human civilization live 150 years in a nuclear-powered aircraft carrier colony without resorting to mass killing/ cannibalism?

Is there reliable evidence that depleted uranium from the 1999 NATO bombing is causing cancer in Serbia?

Is it okay to fade a human face just to create some space to place important content over it?

Closest Proximity of Oceans to Freshwater Springs

Most important new papers in computational complexity

Is is okay to submit a paper from a master's thesis without informing the advisor?

What's the safest way to inform a new user of their password on an invite-only website?

Is there a canon reason why Klingon and Romulan vessels are so similar in shape?

Single level file directory

What game is this character in the Pixels movie from?

Is there any way to adjust the component values to get 5V output?

Do home values typically rise and fall at a consistent percent?

Who voices the character "Finger" in The Fifth Element?

Using “ser” without "un/una"?

Can European countries bypass the EU and make their own individual trade deal with the U.S.?

Stars left to theorem (for exercises)



VBA CopyFolder copying wrong folder


Sending formatted Lotus Notes rich text email from Excel VBAIs there a way to crack the password on an Excel VBA Project?How to return a result from a VBA functionLoop through files in a folder using VBA?How to avoid using Select in Excel VBACopy Excel cells, evaluate content, and copy a file looping over the cell contents as filenameCopy data from worksheet to html file to mailMkDir not accepting variable argument (EXCEL-VBA)how to convert a column of text with html tags to formatted text in vba in excelVBA Copy Data goes wrong






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I've got a small macro that is supposed to copy a folder and all its contents from one filepath to another. The problem is, it's copying the wrong folder. It instead copies the first subfolder (but not its contents) from that folder and then errors out with a "Path not found" error. Occasionally it will copy the main folder and then just that same first subfolder with none of its contents and then again error out with "Path not found".



 Dim strFilePath As String, techfolder As String

strFilePath = "G:DataFolderNamePROJECTS2019AnotherFolderNameTest_Area" & year2 & " - Testing6. Verification" & quarter & "3 - Verification Emails ReceivedYetAnotherFolderName"

techfolder = "G:DataCompanyNameFolderNameAnotherFolderNameName" & year2 & " " & quarter2 & "Completed"

Dim FSO As Object

If Right(techfolder, 1) = "" Then
techfolder = Left(techfolder, Len(techfolder) - 1)
End If

If Right(strFilePath, 1) = "" Then
strFilePath = Left(strFilePath, Len(strFilePath) - 1)
End If

Set FSO = CreateObject("scripting.filesystemobject")

If FSO.FolderExists(techfolder) = False Then
MsgBox techfolder & " doesn't exist"
Exit Sub
End If
Debug.Print (strFilePath)
Debug.Print (techfolder)
FSO.CopyFolder Source:=techfolder, Destination:=strFilePath
MsgBox "You can find the files and subfolders from " & techfolder & " in " & strFilePath


I've tried a couple different methods of the CopyFolder with if logic, etc. from some internet searches but all in this general form. None of them copy the folder and all its subfolders/contents correctly.



I've checked my filepaths via the debug, they are fine and I can copy/paste them into file explorer and navigate with no issue. Additionally the subfolder copying implies that it seems to be correct.



Manually copying the folder or its subfolder has no issues.



ETA: There are about 31 sub folders and each contains one excel and one pdf.



Variable Values are:



Quarter is Q3 2018
Year2 is 2018
Quarter2 is Q3



Year2 and Quarter2 are made by substrings of Quarter, a variable that is populated via an inputbox.



 year2 = Mid(quarter, 4, 4)
quarter2 = Mid(quarter, 1, 2)









share|improve this question
























  • Your code works for me at least with some test directores and files I created. Are the folder names extremely long?

    – Storax
    Mar 25 at 14:14











  • The longest is around 53 characters; but that one's further down in the list. It isn't even making it that far. The main folder name is "Completed" and that's not even getting copied sometimes. Sometimes it just goes straight to the sub-folder which is in the format "REQ-#### Firstname Lastname"

    – M. R.
    Mar 25 at 14:18











  • Do you use any wildcards in one of the pathnames?

    – Storax
    Mar 25 at 14:20












  • No, I use some variable calls for year/quarter, but no wildcards.

    – M. R.
    Mar 25 at 14:22











  • Is it possible for you to add the actual values of strFilePath and techfolder to your posting? Maybe this gives a clue. Otherwise I do not know what's wrong.

    – Storax
    Mar 25 at 14:23


















0















I've got a small macro that is supposed to copy a folder and all its contents from one filepath to another. The problem is, it's copying the wrong folder. It instead copies the first subfolder (but not its contents) from that folder and then errors out with a "Path not found" error. Occasionally it will copy the main folder and then just that same first subfolder with none of its contents and then again error out with "Path not found".



 Dim strFilePath As String, techfolder As String

strFilePath = "G:DataFolderNamePROJECTS2019AnotherFolderNameTest_Area" & year2 & " - Testing6. Verification" & quarter & "3 - Verification Emails ReceivedYetAnotherFolderName"

techfolder = "G:DataCompanyNameFolderNameAnotherFolderNameName" & year2 & " " & quarter2 & "Completed"

Dim FSO As Object

If Right(techfolder, 1) = "" Then
techfolder = Left(techfolder, Len(techfolder) - 1)
End If

If Right(strFilePath, 1) = "" Then
strFilePath = Left(strFilePath, Len(strFilePath) - 1)
End If

Set FSO = CreateObject("scripting.filesystemobject")

If FSO.FolderExists(techfolder) = False Then
MsgBox techfolder & " doesn't exist"
Exit Sub
End If
Debug.Print (strFilePath)
Debug.Print (techfolder)
FSO.CopyFolder Source:=techfolder, Destination:=strFilePath
MsgBox "You can find the files and subfolders from " & techfolder & " in " & strFilePath


I've tried a couple different methods of the CopyFolder with if logic, etc. from some internet searches but all in this general form. None of them copy the folder and all its subfolders/contents correctly.



I've checked my filepaths via the debug, they are fine and I can copy/paste them into file explorer and navigate with no issue. Additionally the subfolder copying implies that it seems to be correct.



Manually copying the folder or its subfolder has no issues.



ETA: There are about 31 sub folders and each contains one excel and one pdf.



Variable Values are:



Quarter is Q3 2018
Year2 is 2018
Quarter2 is Q3



Year2 and Quarter2 are made by substrings of Quarter, a variable that is populated via an inputbox.



 year2 = Mid(quarter, 4, 4)
quarter2 = Mid(quarter, 1, 2)









share|improve this question
























  • Your code works for me at least with some test directores and files I created. Are the folder names extremely long?

    – Storax
    Mar 25 at 14:14











  • The longest is around 53 characters; but that one's further down in the list. It isn't even making it that far. The main folder name is "Completed" and that's not even getting copied sometimes. Sometimes it just goes straight to the sub-folder which is in the format "REQ-#### Firstname Lastname"

    – M. R.
    Mar 25 at 14:18











  • Do you use any wildcards in one of the pathnames?

    – Storax
    Mar 25 at 14:20












  • No, I use some variable calls for year/quarter, but no wildcards.

    – M. R.
    Mar 25 at 14:22











  • Is it possible for you to add the actual values of strFilePath and techfolder to your posting? Maybe this gives a clue. Otherwise I do not know what's wrong.

    – Storax
    Mar 25 at 14:23














0












0








0








I've got a small macro that is supposed to copy a folder and all its contents from one filepath to another. The problem is, it's copying the wrong folder. It instead copies the first subfolder (but not its contents) from that folder and then errors out with a "Path not found" error. Occasionally it will copy the main folder and then just that same first subfolder with none of its contents and then again error out with "Path not found".



 Dim strFilePath As String, techfolder As String

strFilePath = "G:DataFolderNamePROJECTS2019AnotherFolderNameTest_Area" & year2 & " - Testing6. Verification" & quarter & "3 - Verification Emails ReceivedYetAnotherFolderName"

techfolder = "G:DataCompanyNameFolderNameAnotherFolderNameName" & year2 & " " & quarter2 & "Completed"

Dim FSO As Object

If Right(techfolder, 1) = "" Then
techfolder = Left(techfolder, Len(techfolder) - 1)
End If

If Right(strFilePath, 1) = "" Then
strFilePath = Left(strFilePath, Len(strFilePath) - 1)
End If

Set FSO = CreateObject("scripting.filesystemobject")

If FSO.FolderExists(techfolder) = False Then
MsgBox techfolder & " doesn't exist"
Exit Sub
End If
Debug.Print (strFilePath)
Debug.Print (techfolder)
FSO.CopyFolder Source:=techfolder, Destination:=strFilePath
MsgBox "You can find the files and subfolders from " & techfolder & " in " & strFilePath


I've tried a couple different methods of the CopyFolder with if logic, etc. from some internet searches but all in this general form. None of them copy the folder and all its subfolders/contents correctly.



I've checked my filepaths via the debug, they are fine and I can copy/paste them into file explorer and navigate with no issue. Additionally the subfolder copying implies that it seems to be correct.



Manually copying the folder or its subfolder has no issues.



ETA: There are about 31 sub folders and each contains one excel and one pdf.



Variable Values are:



Quarter is Q3 2018
Year2 is 2018
Quarter2 is Q3



Year2 and Quarter2 are made by substrings of Quarter, a variable that is populated via an inputbox.



 year2 = Mid(quarter, 4, 4)
quarter2 = Mid(quarter, 1, 2)









share|improve this question
















I've got a small macro that is supposed to copy a folder and all its contents from one filepath to another. The problem is, it's copying the wrong folder. It instead copies the first subfolder (but not its contents) from that folder and then errors out with a "Path not found" error. Occasionally it will copy the main folder and then just that same first subfolder with none of its contents and then again error out with "Path not found".



 Dim strFilePath As String, techfolder As String

strFilePath = "G:DataFolderNamePROJECTS2019AnotherFolderNameTest_Area" & year2 & " - Testing6. Verification" & quarter & "3 - Verification Emails ReceivedYetAnotherFolderName"

techfolder = "G:DataCompanyNameFolderNameAnotherFolderNameName" & year2 & " " & quarter2 & "Completed"

Dim FSO As Object

If Right(techfolder, 1) = "" Then
techfolder = Left(techfolder, Len(techfolder) - 1)
End If

If Right(strFilePath, 1) = "" Then
strFilePath = Left(strFilePath, Len(strFilePath) - 1)
End If

Set FSO = CreateObject("scripting.filesystemobject")

If FSO.FolderExists(techfolder) = False Then
MsgBox techfolder & " doesn't exist"
Exit Sub
End If
Debug.Print (strFilePath)
Debug.Print (techfolder)
FSO.CopyFolder Source:=techfolder, Destination:=strFilePath
MsgBox "You can find the files and subfolders from " & techfolder & " in " & strFilePath


I've tried a couple different methods of the CopyFolder with if logic, etc. from some internet searches but all in this general form. None of them copy the folder and all its subfolders/contents correctly.



I've checked my filepaths via the debug, they are fine and I can copy/paste them into file explorer and navigate with no issue. Additionally the subfolder copying implies that it seems to be correct.



Manually copying the folder or its subfolder has no issues.



ETA: There are about 31 sub folders and each contains one excel and one pdf.



Variable Values are:



Quarter is Q3 2018
Year2 is 2018
Quarter2 is Q3



Year2 and Quarter2 are made by substrings of Quarter, a variable that is populated via an inputbox.



 year2 = Mid(quarter, 4, 4)
quarter2 = Mid(quarter, 1, 2)






excel vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 14:57







M. R.

















asked Mar 25 at 14:00









M. R.M. R.

64 bronze badges




64 bronze badges












  • Your code works for me at least with some test directores and files I created. Are the folder names extremely long?

    – Storax
    Mar 25 at 14:14











  • The longest is around 53 characters; but that one's further down in the list. It isn't even making it that far. The main folder name is "Completed" and that's not even getting copied sometimes. Sometimes it just goes straight to the sub-folder which is in the format "REQ-#### Firstname Lastname"

    – M. R.
    Mar 25 at 14:18











  • Do you use any wildcards in one of the pathnames?

    – Storax
    Mar 25 at 14:20












  • No, I use some variable calls for year/quarter, but no wildcards.

    – M. R.
    Mar 25 at 14:22











  • Is it possible for you to add the actual values of strFilePath and techfolder to your posting? Maybe this gives a clue. Otherwise I do not know what's wrong.

    – Storax
    Mar 25 at 14:23


















  • Your code works for me at least with some test directores and files I created. Are the folder names extremely long?

    – Storax
    Mar 25 at 14:14











  • The longest is around 53 characters; but that one's further down in the list. It isn't even making it that far. The main folder name is "Completed" and that's not even getting copied sometimes. Sometimes it just goes straight to the sub-folder which is in the format "REQ-#### Firstname Lastname"

    – M. R.
    Mar 25 at 14:18











  • Do you use any wildcards in one of the pathnames?

    – Storax
    Mar 25 at 14:20












  • No, I use some variable calls for year/quarter, but no wildcards.

    – M. R.
    Mar 25 at 14:22











  • Is it possible for you to add the actual values of strFilePath and techfolder to your posting? Maybe this gives a clue. Otherwise I do not know what's wrong.

    – Storax
    Mar 25 at 14:23

















Your code works for me at least with some test directores and files I created. Are the folder names extremely long?

– Storax
Mar 25 at 14:14





Your code works for me at least with some test directores and files I created. Are the folder names extremely long?

– Storax
Mar 25 at 14:14













The longest is around 53 characters; but that one's further down in the list. It isn't even making it that far. The main folder name is "Completed" and that's not even getting copied sometimes. Sometimes it just goes straight to the sub-folder which is in the format "REQ-#### Firstname Lastname"

– M. R.
Mar 25 at 14:18





The longest is around 53 characters; but that one's further down in the list. It isn't even making it that far. The main folder name is "Completed" and that's not even getting copied sometimes. Sometimes it just goes straight to the sub-folder which is in the format "REQ-#### Firstname Lastname"

– M. R.
Mar 25 at 14:18













Do you use any wildcards in one of the pathnames?

– Storax
Mar 25 at 14:20






Do you use any wildcards in one of the pathnames?

– Storax
Mar 25 at 14:20














No, I use some variable calls for year/quarter, but no wildcards.

– M. R.
Mar 25 at 14:22





No, I use some variable calls for year/quarter, but no wildcards.

– M. R.
Mar 25 at 14:22













Is it possible for you to add the actual values of strFilePath and techfolder to your posting? Maybe this gives a clue. Otherwise I do not know what's wrong.

– Storax
Mar 25 at 14:23






Is it possible for you to add the actual values of strFilePath and techfolder to your posting? Maybe this gives a clue. Otherwise I do not know what's wrong.

– Storax
Mar 25 at 14:23













0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55339551%2fvba-copyfolder-copying-wrong-folder%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55339551%2fvba-copyfolder-copying-wrong-folder%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해