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;
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
|
show 5 more comments
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
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 ofstrFilePathandtechfolderto your posting? Maybe this gives a clue. Otherwise I do not know what's wrong.
– Storax
Mar 25 at 14:23
|
show 5 more comments
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
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
excel vba
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 ofstrFilePathandtechfolderto your posting? Maybe this gives a clue. Otherwise I do not know what's wrong.
– Storax
Mar 25 at 14:23
|
show 5 more comments
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 ofstrFilePathandtechfolderto 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
|
show 5 more comments
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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
strFilePathandtechfolderto your posting? Maybe this gives a clue. Otherwise I do not know what's wrong.– Storax
Mar 25 at 14:23