View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default Import through dialogbox

Oops. Please ignore the previous post

Replace the below 4 line code
'Dim ws As Worksheet
'For Each ws In wb.Worksheets
'ws.Copy xb.Worksheets(1)
'Next ws

'to import the 1st sheet
wb.Worksheets(1).Copy xb.Worksheets(1)

'to import the 2nd sheet
wb.Worksheets(2).Copy xb.Worksheets(1)

'to import the any sheet
wb.Worksheets("sheetname").Copy xb.Worksheets(1)

--
If this post helps click Yes
---------------
Jacob Skaria


"Sverre" wrote:

I found this program to import many worksheets from different location.
1. How can I change it to stop after one choice ?
2. How can I change it to stop after two choice ?


Sub GetSheets()

Dim s As String

Dim fd As FileDialog
Dim ffs As FileDialogFilters
Dim wb As Workbook
Dim xb As Workbook
Set xb = ActiveWorkbook

'Get user to pick file
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
Set ffs = .Filters
With ffs
.Clear
.Add "Excel Files", "*.xls"
End With
.AllowMultiSelect = False
If .Show Then s = .SelectedItems(1)
End With

'Turn off prompts
Application.DisplayAlerts = False

'Open chosen workbook
Set wb = Workbooks.Open(s, False)

Dim ws As Worksheet
For Each ws In wb.Worksheets
ws.Copy xb.Worksheets(1)
Next ws


'Close workbook
wb.Close

'Switch prompts back on
Application.DisplayAlerts = True

End Sub