Only to import the sheet with the name in Range Q1

KlausW

Active Member
Joined
Sep 9, 2020
Messages
378
Office Version
  1. 2016
Platform
  1. 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

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
 
Sorry to say, I can get it to work, get this error Pth = GetFolder() Sub or Function not defined.
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Do you still have the GetFolder function, or have you deleted it?
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,791
Messages
6,121,611
Members
449,038
Latest member
apwr

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