Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.
Public Sub ImportWksheet() 'On Error GoTo ErrHandler Dim DstWkb As Workbook Dim FileFilter As String Dim Filename As String Dim SrcWkb As Workbook Dim srcWks As String Dim dstWks As String srcWks = "Sheet1" 'Name of the Worksheet to be copied dstWks = "Import" 'Name the copied Worksheet will be given FileFilter = "Excel Files, *.xls;*.xla;*.csv, All Files, *.*" Filename = Application.GetOpenFilename(FileFilter, 1) If Filename = "False" Then Exit Sub Set DstWkb = ThisWorkbook Set SrcWkb = Workbooks.Open(Filename:=Filename, ReadOnly:=True) Application.ScreenUpdating = False 'On Error Resume Next With SrcWkb.Worksheets(srcWks) If Err.Number = 9 Then MsgBox srcWks & " was not found in " & SrcWkb.Name GoTo OrderlyExit End If 'On Error GoTo 0 .Copy After:=DstWkb.Worksheets(DstWkb.Worksheets.Count) 'On Error Resume Next ActiveSheet.Name = dstWks If Err.Number = 1004 Then MsgBox dstWks & " already exists in " & DstWkb.Name & vbCrLf _ & "Two worksheets can not have the same name." GoTo OrderlyExit End If 'On Error GoTo 0 End With OrderlyExit: Application.ScreenUpdating = True SrcWkb.Close SaveChanges:=False ysnValid = True ErrHandler: ' MsgBox "Failed to Import to database. Check database is not read-only." 'Exit Sub End Sub
Join the community of 500,000 technology professionals and ask your questions.