Copy specific worksheet from multiple workbooks to a master workbook












0














I am trying to copy a specific worksheet (called "Edit") from a folder full of workbooks (190). I have the following code to do this:



Option Explicit
Sub CombineSheets()
Dim sPath As String
Dim sFname As String
Dim wBk As Workbook
Dim wSht As Variant

Application.EnableEvents = False
Application.ScreenUpdating = False
sPath = InputBox("M:Employee InformationPeter YoungMsc Project1 - 181028 - Office First FloorMacroCopy")
ChDir sPath
sFname = InputBox("*")
sFname = Dir(sPath & "" & sFname & ".xl*", vbNormal)
wSht = InputBox("Edit")
Do Until sFname = ""
Set wBk = Workbooks.Open(sFname)
Windows(sFname).Activate
Sheets(wSht).Copy Before:=ThisWorkbook.Sheets(1)
wBk.Close False
sFname = Dir()
Loop
ActiveWorkbook.Save
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub


When I run the Macro, I get the dialog box asking to name the sheet to copy from all matching workbooks. I enter Edit, and get the message 'Run-time error '76': Path not found' Can anyone tell me what needs to be changed in the code to make this work.?










share|improve this question
























  • Welcome to SO. Please, specify which line raises the error. Also, when you execute Workbooks.Open(sFname) , can you tell what is the value of sFname?
    – Foxfire And Burns And Burns
    Nov 23 '18 at 9:51










  • I think the error is in ChDir sPath, when I debug - run to cursor this is the line that is highlighted. I'm not quite sure what you mean about the second point, could you explain further. Is this something that I should define?
    – Peter Young
    Nov 23 '18 at 10:18










  • What is the value stored in sFname when you execute the code? Try debugging your code. Execute it with F8 (Step by step) and the code will go line by line. By holding the cursor steady on a variable, you can see the value of the variable :) . Please, check this link to learn how to debug code excel-easy.com/vba/examples/debugging.html
    – Foxfire And Burns And Burns
    Nov 23 '18 at 10:49










  • Ok, when I execute line by line it seems to get to ChDir sPath then comes up with the run time error above. The value of Workbooks.Open(sFname) = ""
    – Peter Young
    Nov 23 '18 at 11:57










  • Then sFname is not getting the value you need. You must hanlde it in the previous lines. Does sFname = Dir(sPath & "" & sFname & ".xl*", vbNormal) work properly with that *? Also, if you want to loop trought files of a specific folder, check Loop through files in a folder using VBA?
    – Foxfire And Burns And Burns
    Nov 23 '18 at 12:49


















0














I am trying to copy a specific worksheet (called "Edit") from a folder full of workbooks (190). I have the following code to do this:



Option Explicit
Sub CombineSheets()
Dim sPath As String
Dim sFname As String
Dim wBk As Workbook
Dim wSht As Variant

Application.EnableEvents = False
Application.ScreenUpdating = False
sPath = InputBox("M:Employee InformationPeter YoungMsc Project1 - 181028 - Office First FloorMacroCopy")
ChDir sPath
sFname = InputBox("*")
sFname = Dir(sPath & "" & sFname & ".xl*", vbNormal)
wSht = InputBox("Edit")
Do Until sFname = ""
Set wBk = Workbooks.Open(sFname)
Windows(sFname).Activate
Sheets(wSht).Copy Before:=ThisWorkbook.Sheets(1)
wBk.Close False
sFname = Dir()
Loop
ActiveWorkbook.Save
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub


When I run the Macro, I get the dialog box asking to name the sheet to copy from all matching workbooks. I enter Edit, and get the message 'Run-time error '76': Path not found' Can anyone tell me what needs to be changed in the code to make this work.?










share|improve this question
























  • Welcome to SO. Please, specify which line raises the error. Also, when you execute Workbooks.Open(sFname) , can you tell what is the value of sFname?
    – Foxfire And Burns And Burns
    Nov 23 '18 at 9:51










  • I think the error is in ChDir sPath, when I debug - run to cursor this is the line that is highlighted. I'm not quite sure what you mean about the second point, could you explain further. Is this something that I should define?
    – Peter Young
    Nov 23 '18 at 10:18










  • What is the value stored in sFname when you execute the code? Try debugging your code. Execute it with F8 (Step by step) and the code will go line by line. By holding the cursor steady on a variable, you can see the value of the variable :) . Please, check this link to learn how to debug code excel-easy.com/vba/examples/debugging.html
    – Foxfire And Burns And Burns
    Nov 23 '18 at 10:49










  • Ok, when I execute line by line it seems to get to ChDir sPath then comes up with the run time error above. The value of Workbooks.Open(sFname) = ""
    – Peter Young
    Nov 23 '18 at 11:57










  • Then sFname is not getting the value you need. You must hanlde it in the previous lines. Does sFname = Dir(sPath & "" & sFname & ".xl*", vbNormal) work properly with that *? Also, if you want to loop trought files of a specific folder, check Loop through files in a folder using VBA?
    – Foxfire And Burns And Burns
    Nov 23 '18 at 12:49
















0












0








0







I am trying to copy a specific worksheet (called "Edit") from a folder full of workbooks (190). I have the following code to do this:



Option Explicit
Sub CombineSheets()
Dim sPath As String
Dim sFname As String
Dim wBk As Workbook
Dim wSht As Variant

Application.EnableEvents = False
Application.ScreenUpdating = False
sPath = InputBox("M:Employee InformationPeter YoungMsc Project1 - 181028 - Office First FloorMacroCopy")
ChDir sPath
sFname = InputBox("*")
sFname = Dir(sPath & "" & sFname & ".xl*", vbNormal)
wSht = InputBox("Edit")
Do Until sFname = ""
Set wBk = Workbooks.Open(sFname)
Windows(sFname).Activate
Sheets(wSht).Copy Before:=ThisWorkbook.Sheets(1)
wBk.Close False
sFname = Dir()
Loop
ActiveWorkbook.Save
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub


When I run the Macro, I get the dialog box asking to name the sheet to copy from all matching workbooks. I enter Edit, and get the message 'Run-time error '76': Path not found' Can anyone tell me what needs to be changed in the code to make this work.?










share|improve this question















I am trying to copy a specific worksheet (called "Edit") from a folder full of workbooks (190). I have the following code to do this:



Option Explicit
Sub CombineSheets()
Dim sPath As String
Dim sFname As String
Dim wBk As Workbook
Dim wSht As Variant

Application.EnableEvents = False
Application.ScreenUpdating = False
sPath = InputBox("M:Employee InformationPeter YoungMsc Project1 - 181028 - Office First FloorMacroCopy")
ChDir sPath
sFname = InputBox("*")
sFname = Dir(sPath & "" & sFname & ".xl*", vbNormal)
wSht = InputBox("Edit")
Do Until sFname = ""
Set wBk = Workbooks.Open(sFname)
Windows(sFname).Activate
Sheets(wSht).Copy Before:=ThisWorkbook.Sheets(1)
wBk.Close False
sFname = Dir()
Loop
ActiveWorkbook.Save
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub


When I run the Macro, I get the dialog box asking to name the sheet to copy from all matching workbooks. I enter Edit, and get the message 'Run-time error '76': Path not found' Can anyone tell me what needs to be changed in the code to make this work.?







excel vba excel-vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 10:58









Dominique

1,77441539




1,77441539










asked Nov 23 '18 at 9:35









Peter Young

182




182












  • Welcome to SO. Please, specify which line raises the error. Also, when you execute Workbooks.Open(sFname) , can you tell what is the value of sFname?
    – Foxfire And Burns And Burns
    Nov 23 '18 at 9:51










  • I think the error is in ChDir sPath, when I debug - run to cursor this is the line that is highlighted. I'm not quite sure what you mean about the second point, could you explain further. Is this something that I should define?
    – Peter Young
    Nov 23 '18 at 10:18










  • What is the value stored in sFname when you execute the code? Try debugging your code. Execute it with F8 (Step by step) and the code will go line by line. By holding the cursor steady on a variable, you can see the value of the variable :) . Please, check this link to learn how to debug code excel-easy.com/vba/examples/debugging.html
    – Foxfire And Burns And Burns
    Nov 23 '18 at 10:49










  • Ok, when I execute line by line it seems to get to ChDir sPath then comes up with the run time error above. The value of Workbooks.Open(sFname) = ""
    – Peter Young
    Nov 23 '18 at 11:57










  • Then sFname is not getting the value you need. You must hanlde it in the previous lines. Does sFname = Dir(sPath & "" & sFname & ".xl*", vbNormal) work properly with that *? Also, if you want to loop trought files of a specific folder, check Loop through files in a folder using VBA?
    – Foxfire And Burns And Burns
    Nov 23 '18 at 12:49




















  • Welcome to SO. Please, specify which line raises the error. Also, when you execute Workbooks.Open(sFname) , can you tell what is the value of sFname?
    – Foxfire And Burns And Burns
    Nov 23 '18 at 9:51










  • I think the error is in ChDir sPath, when I debug - run to cursor this is the line that is highlighted. I'm not quite sure what you mean about the second point, could you explain further. Is this something that I should define?
    – Peter Young
    Nov 23 '18 at 10:18










  • What is the value stored in sFname when you execute the code? Try debugging your code. Execute it with F8 (Step by step) and the code will go line by line. By holding the cursor steady on a variable, you can see the value of the variable :) . Please, check this link to learn how to debug code excel-easy.com/vba/examples/debugging.html
    – Foxfire And Burns And Burns
    Nov 23 '18 at 10:49










  • Ok, when I execute line by line it seems to get to ChDir sPath then comes up with the run time error above. The value of Workbooks.Open(sFname) = ""
    – Peter Young
    Nov 23 '18 at 11:57










  • Then sFname is not getting the value you need. You must hanlde it in the previous lines. Does sFname = Dir(sPath & "" & sFname & ".xl*", vbNormal) work properly with that *? Also, if you want to loop trought files of a specific folder, check Loop through files in a folder using VBA?
    – Foxfire And Burns And Burns
    Nov 23 '18 at 12:49


















Welcome to SO. Please, specify which line raises the error. Also, when you execute Workbooks.Open(sFname) , can you tell what is the value of sFname?
– Foxfire And Burns And Burns
Nov 23 '18 at 9:51




Welcome to SO. Please, specify which line raises the error. Also, when you execute Workbooks.Open(sFname) , can you tell what is the value of sFname?
– Foxfire And Burns And Burns
Nov 23 '18 at 9:51












I think the error is in ChDir sPath, when I debug - run to cursor this is the line that is highlighted. I'm not quite sure what you mean about the second point, could you explain further. Is this something that I should define?
– Peter Young
Nov 23 '18 at 10:18




I think the error is in ChDir sPath, when I debug - run to cursor this is the line that is highlighted. I'm not quite sure what you mean about the second point, could you explain further. Is this something that I should define?
– Peter Young
Nov 23 '18 at 10:18












What is the value stored in sFname when you execute the code? Try debugging your code. Execute it with F8 (Step by step) and the code will go line by line. By holding the cursor steady on a variable, you can see the value of the variable :) . Please, check this link to learn how to debug code excel-easy.com/vba/examples/debugging.html
– Foxfire And Burns And Burns
Nov 23 '18 at 10:49




What is the value stored in sFname when you execute the code? Try debugging your code. Execute it with F8 (Step by step) and the code will go line by line. By holding the cursor steady on a variable, you can see the value of the variable :) . Please, check this link to learn how to debug code excel-easy.com/vba/examples/debugging.html
– Foxfire And Burns And Burns
Nov 23 '18 at 10:49












Ok, when I execute line by line it seems to get to ChDir sPath then comes up with the run time error above. The value of Workbooks.Open(sFname) = ""
– Peter Young
Nov 23 '18 at 11:57




Ok, when I execute line by line it seems to get to ChDir sPath then comes up with the run time error above. The value of Workbooks.Open(sFname) = ""
– Peter Young
Nov 23 '18 at 11:57












Then sFname is not getting the value you need. You must hanlde it in the previous lines. Does sFname = Dir(sPath & "" & sFname & ".xl*", vbNormal) work properly with that *? Also, if you want to loop trought files of a specific folder, check Loop through files in a folder using VBA?
– Foxfire And Burns And Burns
Nov 23 '18 at 12:49






Then sFname is not getting the value you need. You must hanlde it in the previous lines. Does sFname = Dir(sPath & "" & sFname & ".xl*", vbNormal) work properly with that *? Also, if you want to loop trought files of a specific folder, check Loop through files in a folder using VBA?
– Foxfire And Burns And Burns
Nov 23 '18 at 12:49














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%2f53443989%2fcopy-specific-worksheet-from-multiple-workbooks-to-a-master-workbook%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
















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53443989%2fcopy-specific-worksheet-from-multiple-workbooks-to-a-master-workbook%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

Trompette piccolo

Slow SSRS Report in dynamic grouping and multiple parameters

Simon Yates (cyclisme)