+ Reply to Thread
Results 1 to 2 of 2

Want to import data (.csv and .xml) into active workbook with a sheet that I specify

Hybrid View

vossy51 Want to import data (.csv and... 04-08-2013, 02:25 AM
AndyLitch Re: Want to import data (.csv... 04-08-2013, 02:37 AM
  1. #1
    Registered User
    Join Date
    04-05-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    10

    Want to import data (.csv and .xml) into active workbook with a sheet that I specify

    Hi, new to this sort of programming.
    What i am after is to have my excel sheet open, hit an import button to bring in either an .xml, or .csv file which user can select using GetOpenFilename.
    I have written the following, my issue is that when it pastes the data into my workbook , it always goes into sheet #1, which contains the button.

    [I]Sub GetCSV()
    Dim strFile As String
    Dim wkb1 As Workbook
    Dim wkb2 As Workbook

    Set wkb1 = ActiveWorkbook

    strFile = Application.GetOpenFilename
    If strFile = "False" Then Exit Sub
    ' false means no file selected
    Workbooks.Open strFile
    ' set active workbook
    Set wkb2 = ActiveWorkbook
    wkb2.ActiveSheet.Range("A1:GP350").Copy Destination:=wkb1.ActiveSheet _
    .Range("A5:GP350")

    'wkb2.Range("A1:GP350").Copy Destination:=wkb1.Range("A5:GP350")
    wkb2.Close SaveChanges:=False
    End Sub

    How can i alter this to allow me to select sheet4 or in my case ConfigData Sheet as I have renamed sheet #4 to this name?
    Have tried heaps of stuff with no joy...
    Any help greatly appreciated.

    Thanks,
    Vossy51

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Want to import data (.csv and .xml) into active workbook with a sheet that I specify

    'wkb2.Range("A1:GP350").Copy Destination:=wkb1.sheet4.Range("A5:GP350")
    wkb2.Close SaveChanges:=False
    Elegant Simplicity............. Not Always

+ Reply to Thread

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