Xml data import

petep

New Member
Joined
Nov 20, 2013
Messages
11
Hi I need some help, I recorded a Macro which imports an excel file using the XML Data import function in the data ribbon. the code is below, but the issue i am having is on the name of the file. I have bolded the area that changes daily. the file name changes everyday. is there anyway to make that part that changes a wildcard so i dont have to worry about the daily name change?


Code:
Sub ()
'
Application.ScreenUpdating = False


Clear




    DF = Format(Sheets("Last Night COB").Range("D1"), "yyyymmdd")
    DF1 = Format(Sheets("Last Night COB").Range("D1"), "mmddyyyy")
    DF2 = Format(Sheets("Last Night COB").Range("F1"), "yyyymmdd")
    DF3 = Format(Sheets("Last Night COB").Range("F2"), "yyyymmdd")
    DF4 = Format(Sheets("Last Night COB").Range("F1"), "mmddyyyy")
'
    Sheets("Last Night COB").Select
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
        "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=C" & DF2 & "\MANAGEMENT LP - VAR" _
        , _
        " SWAP - DAILY[B]-01-Mar-2016-109333523[/B].XLS;Mode=Share Deny Write;Extended Properties=""HDR=YES;"";Jet OLEDB:System database="""";Jet OL" _
        , _
        "EDB:Registry Path="""";Jet OLEDB:Database 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=Fals" _
        , _
        "e;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;J" _
        , _
        "et OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False" _
        ), Destination:=Range("$A$8")).QueryTable
        .CommandType = xlCmdTable
        .CommandText = Array("'Equity-T1$'")
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .SourceDataFile = _
        "I:\RawhideData\Email\" & DF2 & "\MANAGEMENT LP - VAR SWAP - DAILY[B]-01-Mar-2016-109333523[/B].XLS"
        .ListObject.DisplayName = _
        "Table_MANAGEMENT_LP___VAR_SWAP___DAILY[B]_01_Mar_2016_109333523[/B]"
        .Refresh BackgroundQuery:=False
    End With
    
    Sheets("Last Night COB").Select
    Range("A11").Select
    ActiveSheet.ListObjects( _
        "Table_MANAGEMENT_LP___VAR_SWAP___DAILY[B]_01_Mar_2016_109333523[/B]").Unlist
    Rows("7:8").Select
    Selection.Delete Shift:=xlUp

this seems to work but i cant figure out the other parts.
Code:
        "I:\RawhideData\Email\" & DF2 & "\MANAGEMENT LP - VAR SWAP - DAILY[B]*[/B].XLS"

thanks everyone!
 
Last edited:

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,215,743
Messages
6,126,609
Members
449,321
Latest member
syzer

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top