Import all sheets from another workbook

User avatar
Joseph
3StarLounger
Posts: 206
Joined: 31 Dec 2010, 22:23
Location: Columbia Falls, MT

Import all sheets from another workbook

Post by Joseph »

Sweet Hans, thanks.

Would you happen to know of some code I could assign to a command button to do the following:
Open browse window
Import all sheets within the selected workbook in to the active workbook?

Google is giving me nothing, not sure if it's even possible.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Import all sheets from another workbook

Post by HansV »

I have moved this question to a thread of its own since it is not related to the subject of ListBox Issue.

Try this:

Code: Select all

Sub ImportSheets()
  Dim wbkSrc As Workbook
  Dim wbkTrg As Workbook
  Dim strFileName As String
  strFileName = Application.GetOpenFilename
  If strFileName = "False" Then
    MsgBox "Action canceled", vbInformation
    Exit Sub
  End If
  On Error GoTo ErrHandler
  Application.ScreenUpdating = False
  ' ***** Optional settings *******************
  Application.Calculation = xlCalculationManual
  Application.EnableEvents = False
  ' ***** End of optional settings ************
  Set wbkTrg = ActiveWorkbook
  Set wbkSrc = Workbooks.Open(Filename:=strFileName, ReadOnly:=True)
  wbkSrc.Worksheets.Copy After:=wbkTrg.Worksheets(wbkTrg.Worksheets.Count)
  wbkSrc.Close SaveChanges:=False

ExitHandler:
  Application.EnableEvents = True
  Application.Calculation = xlCalculationAutomatic
  Application.ScreenUpdating = True
  Exit Sub

ErrHandler:
  MsgBox Err.Description, vbExclamation
  Resume ExitHandler
End Sub
Best wishes,
Hans

User avatar
Joseph
3StarLounger
Posts: 206
Joined: 31 Dec 2010, 22:23
Location: Columbia Falls, MT

Re: Import all sheets from another workbook

Post by Joseph »

Yes, I do think we (well I) was a bit off track there.

Anyway. This works amazing!!!!!!!!!!!!!