KlausW
Active Member
- Joined
- Sep 9, 2020
- Messages
- 378
- Office Version
- 2016
- Platform
- Windows
I use this code to import sheets with dialog box, it runs optimally, but I wish Excel only to import the sheets whit the name in Range Q1.
Any help will be much appreciated.
Many Thanks
Klaus W
Any help will be much appreciated.
Many Thanks
Klaus W
VBA Code:
Sub Rektangelafrundedehjørner1_Klik()
Dim ws As Worksheet
Dim Wbk As Workbook
Dim Pth As String, Fname As String
Pth = GetFolder()
Fname = Dir(Pth & "\*.xlsm")
Do While Fname <> ""
Set Wbk = Workbooks.Open(Pth & "\" & Fname)
For Each ws In Wbk.Worksheets
If Not ShtExists(ws.Name, ThisWorkbook) Then
ws.Copy , ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
End If
Next ws
Wbk.Close False
Fname = Dir
Loop
End Sub
Function GetFolder() As String
Dim dlg As FileDialog
Set dlg = Application.FileDialog(msoFileDialogFolderPicker)
'dlg.InitialFileName = "c:\"
'If dlg.Show = -1 Then
'GetFolder = dlg.SelectedItems(1)
'End If
With dlg
.InitialFileName = "c:\"
.Show
GetFolder = .SelectedItems(1)
End With
End Function