+ Reply to Thread
Results 1 to 4 of 4

FileDialog to Import XLS Content

Hybrid View

  1. #1
    Registered User
    Join Date
    10-24-2010
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    2

    FileDialog to Import XLS Content

    I am trying to use a FileDialog(msoFileDialogFilePicker) dialog box to import either delimited text from a file, or content from a XLS sheet (all cells from the first worksheet). I have the delimited-import part working, but I am unable to get the XLS import to work.

    My code is attachd. Any input is appreciated.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: FileDialog to Import XLS Content

    Welcome to the forum!

    In the second QueryTables.Add, change Connection:="TEXT;" to Connection:="ODBC;" and see if that helps.
    Bob
    Click my star if my answer helped you. Mark the thread as [SOLVED] if it has been.

  3. #3
    Registered User
    Join Date
    10-24-2010
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: FileDialog to Import XLS Content

    I appreciate the ODBC idea, but still no data unfortunately.


    Any other input is appreciated.

  4. #4
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: FileDialog to Import XLS Content

    I recorded the following macro by selecting Data->Import External Data->Import Data..., then selecting an Excel file and then Sheet1. This shows what things you need to specify in the ODBC connection string.
        With ActiveSheet.QueryTables.Add(Connection:=Array( _
            "OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\Documents and Settings\lane.bob\Desktop\Excel Forum\A." _
            , _
            "xls;Mode=Share Deny Write;Extended Properties=""HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Datab" _
            , _
            "ase Password="""";Jet OLEDB:Engine Type=35;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global " _
            , _
            "Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;J" _
            , _
            "et OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False" _
            ), Destination:=Range("B17"))
            .CommandType = xlCmdTable
            .CommandText = Array("Sheet1$")
            .Name = "A_1"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .PreserveColumnInfo = True
            .SourceDataFile = _
            "C:\Documents and Settings\lane.bob\Desktop\Excel Forum\A.xls"
            .Refresh BackgroundQuery:=False
        End With
    I suggest you record what you want to have happen and then adapt it to your needs.

+ 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