Results 1 to 2 of 2

Import fails on active sheet

Threaded View

  1. #1
    Registered User
    Join Date
    10-13-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    10

    Import fails on active sheet

    Hello,

    I have taken this codes from web, I had tried to import excel file on active sheet but it does not copy the data from the fetched workbook.

    I want to copy the details of called workbook sheet1 A-D data on the active sheet and close the called workbook.Any other way of doing this with ease.

    Sub OpenSingleFile()
    Dim Filter As String, Title As String
    Dim FilterIndex As Integer
    Dim Filename As Variant
    ' File filters
    Filter = "Excel Files (*.xls),*.xls," & _
            "Text Files (*.txt),*.txt," & _
            "All Files (*.*),*.*"
    ' Default Filter to *.*
    FilterIndex = 3
    Title = "Select a File to Open"
    ChDrive ("C")
    ChDir ("C:\data")
    With Application
    Filename = .GetOpenFilename(Filter, FilterIndex, Title)
    ChDrive (Left(.DefaultFilePath, 1))
     ChDir (.DefaultFilePath)
    End With
    If Filename = False Then
    MsgBox "No file was selected."
    Exit Sub
    End If
    ImportThisOne CStr(Filename)
    End Sub
    Sub ImportThisOne(sFileName As String)
    On Error Resume Next
       Dim oBook As Workbook
       Workbooks.Open sFileName
       Set oBook = ActiveWorkbook
       'Now do your processing on the newly imported sheet
       On Error Resume Next
       'Copy new sheet into this workbook
       oBook.Worksheets(Sheet1).Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
       'close text file, do not save changes
       oBook.Close False
       Set oBook = Nothing
    End Sub
    Last edited by fareen; 06-25-2013 at 03:48 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1