+ Reply to Thread
Results 1 to 2 of 2

VBA Excel: Import variable file name and variable sheet name NEED HELP

Hybrid View

Mark6109 VBA Excel: Import variable... 02-21-2012, 09:31 PM
protonLeah Re: VBA Excel: Import... 02-22-2012, 12:32 AM
  1. #1
    Registered User
    Join Date
    02-21-2012
    Location
    Dallas Texas
    MS-Off Ver
    Excel 2007
    Posts
    1

    VBA Excel: Import variable file name and variable sheet name NEED HELP

    Hi everyone, I need help in order to import 12 files (.csv and .xlsx extensions) from one directory, into one master spreadsheet with multiple tabs. The issue is that the files are dumped onto my company server with time stamps in the file names and sheet names. I have attempted to truncate these stamps off by writing the below code but keep getting a compile error. I have also tried putting an asterisk or wild character in place of the time stamp but keep getting a compile error. Also, in the actual script, I replace the "K:" with the server UNC path. Thanks in advance!!!!

    Sub OLSTest()
    '
    With ActiveSheet.QueryTables.Add(Connection:= _
    "TEXT;K:\OLS_Reports\New Horizon Data Files\AttPendingPutaway_022112.csv", _
    Destination:=Range("$A$1"))
    .Name = "AttPendingPutaway_022112"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .TextFilePromptOnRefresh = False
    .TextFilePlatform = 437
    .TextFileStartRow = 1
    .TextFileParseType = xlDelimited
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileConsecutiveDelimiter = False
    .TextFileTabDelimiter = False
    .TextFileSemicolonDelimiter = False
    .TextFileCommaDelimiter = True
    .TextFileSpaceDelimiter = False
    .TextFileColumnDataTypes = Array(2, 1)
    .TextFileTrailingMinusNumbers = True
    .Refresh BackgroundQuery:=False
    End With
    Sheets("Sheet1").Select
    Sheets("Sheet1").Name = "AttPendingPutawy"
    Sheets("Sheet2").Select
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
    "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=K:\OLS_Reports\New Horizon Data Files\Att28DayEquipmentS" _
    , _
    "hipped_021712.xlsx;Mode=Share Deny Write;Extended Properties=""HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";" _
    , _
    "Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=37;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Je" _
    , _
    "t OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt D" _
    , _
    "atabase=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Je" _
    , _
    "t OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False" _
    ), Destination:=Range("$A$1")).QueryTable
    .CommandType = xlCmdTable
    .CommandText = Array("Att28DayEquipmentShipped_021712$")
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .PreserveColumnInfo = True
    .SourceDataFile = _
    "K:\OLS_Reports\New Horizon Data Files\Att28DayEquipmentShipped_021712.xlsx"
    .ListObject.DisplayName = "Table_Att28DayEquipmentShipped_021712"
    .Refresh BackgroundQuery:=False
    End With
    Sheets("Sheet2").Select
    Sheets("Sheet2").Name = "AttEquipmentShipped"
    End Sub

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,935

    Re: VBA Excel: Import variable file name and variable sheet name NEED HELP

    3. Use code tags around code.
    Posting code without them makes your code hard to read and difficult to be copied for testing.
    Select your code and click the [#] button at the top of the post window
    (if you are editing an existing post, press Go Advanced to see the [#] button).
    The result will appear like this in the post window:


    [code]
    your code here ...
    and here ...
    and here
    [/code]

    ... and appear like this when posted:

    your code here ...
    and here ...
    and here
    You can also type the code tags in manually if you prefer
    Ben Van Johnson

+ 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