Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <blockquote> <blockquote> <p>I don't mind if the files are opened during process. I just didn't want the user to have to open the files individually. I just need them to be able to select or navigate to the desired files</p> </blockquote> </blockquote> </blockquote> <p>Here is a basic code. This code asks user to select two files and then imports the relevant sheet into the current workbook. I have given two options. Take your pick :)</p> <p><strong>TRIED AND TESTED</strong></p> <p><strong>OPTION 1 (Import the Sheets directly instead of copying into sheet1 and 2)</strong></p> <pre><code>Option Explicit Sub Sample() Dim wb1 As Workbook, wb2 As Workbook Dim Ret1, Ret2 Set wb1 = ActiveWorkbook '~~&gt; Get the first File Ret1 = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*", _ , "Please select first file") If Ret1 = False Then Exit Sub '~~&gt; Get the 2nd File Ret2 = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*", _ , "Please select Second file") If Ret2 = False Then Exit Sub Set wb2 = Workbooks.Open(Ret1) wb2.Sheets(1).Copy Before:=wb1.Sheets(1) ActiveSheet.Name = "Blah Blah 1" wb2.Close SaveChanges:=False Set wb2 = Workbooks.Open(Ret2) wb2.Sheets(1).Copy After:=wb1.Sheets(1) ActiveSheet.Name = "Blah Blah 2" wb2.Close SaveChanges:=False Set wb2 = Nothing Set wb1 = Nothing End Sub </code></pre> <p><strong>OPTION 2 (Import the Sheets contents into sheet1 and 2)</strong></p> <pre><code>Option Explicit Sub Sample() Dim wb1 As Workbook, wb2 As Workbook Dim Ret1, Ret2 Set wb1 = ActiveWorkbook '~~&gt; Get the first File Ret1 = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*", _ , "Please select first file") If Ret1 = False Then Exit Sub '~~&gt; Get the 2nd File Ret2 = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*", _ , "Please select Second file") If Ret2 = False Then Exit Sub Set wb2 = Workbooks.Open(Ret1) wb2.Sheets(1).Cells.Copy wb1.Sheets(1).Cells wb2.Close SaveChanges:=False Set wb2 = Workbooks.Open(Ret2) wb2.Sheets(1).Cells.Copy wb1.Sheets(2).Cells wb2.Close SaveChanges:=False Set wb2 = Nothing Set wb1 = Nothing End Sub </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload