Workbooks to tabs

KiloHotel

New Member
Joined
Feb 4, 2018
Messages
42
Office Version
  1. 2016
Platform
  1. Windows
  2. MacOS
Hey guys,

Is there a macro for selecting multiple workbooks and then bring them to a new workbook in tabs?

I have about 2000+ workbooks that I am currently copying and pasting and renaming each tab and it’s a pain!

Any help is appreciated
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
try this...run ImportAllWbs
but you must set the target folder in it.

Rich (BB code):
[Public Sub ImportAllWbs()
getFilesInDir "c:\folder\"
End Sub


Private Sub getFilesInDir(ByVal pvDir)
Dim FSO, oFolder, oFile, oRX, vFile
Dim sTxt As String, sFile As String
Dim wbTarg As Workbook, wbSrc As Workbook
On Error GoTo errGetFiles


Set wbTarg = ActiveWorkbook
If Right(pvDir, 1) <> "\" Then pvDir = pvDir & "\"


Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = FSO.GetFolder(pvDir)


For Each oFile In oFolder.Files
  If InStr(oFile.Name, ".xls") > 0 Then
          'import file here
      vFile = pvDir & oFile.Name
      
     Workbooks.Open vFile
     Set wbSrc = ActiveWorkbook
     wbSrc.Activate
       Sheets(1).Select
       Sheets(1).Copy Before:=wbTarg.Sheets(1)
     wbSrc.Close False
  End If
Next


endit:
Set oFile = Nothing
Set oFolder = Nothing
Set FSO = Nothing
Exit Sub


errGetFiles:
If Err = 3265 Then     'catch error if NO Import table errors
  ' "no errors found"
   Resume Next
Else
  MsgBox Err.Description, , Err
End If
End Sub
 
Upvote 0
No, That didn't work :( Its something to do with the first line of that macro
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,823
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top