Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Import through dialogbox

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Import through dialogbox

If you mean import just one sheet...

Replace the below 3 line code

'For Each ws In wb.Worksheets
'ws.Copy xb.Worksheets(1)
'Next ws

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

'to import the second sheet
ws.Copy xb.Worksheets(2)

'to import any sheet
ws.Copy xb.Worksheets("Sheetname")

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Import through dialogbox

Thank you very much, it works perfect. Answer in one minute, FANTASTIC.

I have an additional question:
Is it possible to give the dialogbox 1 and 2 different name ?
I want the names:

Dialogbox 1: Importer elevdata
Dialogbox 2: Importer lærerdata

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Import through dialogbox

Sverre,

..AllowMultiSelect = False
..Title = "Importer elevdata"

Just after Multiselect option add the title. Multiselect set to True will
allow multiple files to be selected....

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


"Sverre" wrote:

Thank you very much, it works perfect. Answer in one minute, FANTASTIC.

I have an additional question:
Is it possible to give the dialogbox 1 and 2 different name ?
I want the names:

Dialogbox 1: Importer elevdata
Dialogbox 2: Importer lærerdata



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Import through dialogbox

Thank you very much. It works for 1 sheet import. For 2 sheets I got trubble,
but never maind. I can introduce 2 buttons one for each. I am close to end my
task with good help from you. I gess it is to late for me to be an VB
programmer. I startet programming in Fortran for two yers in 1969. After that
I got a new job an have'nt done any programming since then.
Thank you for all help.
I will be back next week with some run time errors I do no understand.
Have a nice weekend

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
reactivate DialogBox oldLearner57 Excel Discussion (Misc queries) 1 September 15th 08 01:02 AM
Open DialogBox in VBA schoujar[_16_] Excel Programming 5 November 4th 05 03:36 AM
DialogBox Layout Patrick Simonds Excel Programming 2 October 1st 05 09:35 PM
OpenFile dialogbox Manu Palao Excel Worksheet Functions 1 November 24th 04 04:27 PM
DialogBox Greg[_12_] Excel Programming 2 September 17th 03 01:41 AM


All times are GMT +1. The time now is 08:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"