VBA to import files with date extension

mrexcelrc

Board Regular
Joined
Oct 14, 2010
Messages
140
Office Version
  1. 365
Platform
  1. Windows
Hello Excel masters!
I am looking for some help to edit my macros below. This macro simply just imports the xml files at then end of each business day. Those files are saved in that location everyday. Additionaly, each file is also saved with a date extension for historical analysis purposes. For example, file "ALPTOTAL_RC_PORTBPV.xml" is also saved as "ALPTOTAL_RC_PORTBPV_20130404.xml". Each of these files are saved with that specific date format extension. How can I enhance this macro so that I can import any historical files for any specific date? For example, if I want to import all these files with date extension "20130226". Please help as I have been trying for 2 days now without any success at all. Thank you very much in advance for your help.:LOL:




ActiveWorkbook.XmlMaps("report_output_Pv01").Import URL:= _
"Q:\Summit\Professional\ALPTOTAL_RC_PORTBPV.xml"
ActiveWorkbook.XmlMaps("report_output_Cflash").Import URL:= _
"Q:\Summit\Professional\CFLASH-ALPTOTAL.xml"
ActiveWorkbook.XmlMaps("report_output_MtM_Futures").Import URL:= _
"Q:\Summit\Professional\plupdMtM_futures.xml"
ActiveWorkbook.XmlMaps("report_output_shftAllcpty_BMA").Import URL:= _
"Q:\Summit\Professional\portrepShift_BMA_allcpty.xml"
ActiveWorkbook.XmlMaps("report_output_shftAllcpty_Libor").Import URL:= _
"Q:\Summit\Professional\portrepShift_allcpty.xml"
ActiveWorkbook.XmlMaps("report_output_shftFuts_Libor").Import URL:= _
"Q:\Summit\Professional\portrepShift_allcpty.xml"
ActiveWorkbook.XmlMaps("report_output_shftNonProfes_BMA").Import URL:= _
"Q:\Summit\Professional\portrepShift_BMA_nonprofes.xml"
ActiveWorkbook.XmlMaps("report_output_shftNonProfes_KNXVL").Import URL:= _
"Q:\Summit\Professional\portrepShift_KNXVL.xml"
ActiveWorkbook.XmlMaps("report_output_shftNonProfes_Libor").Import URL:= _
"Q:\Summit\Professional\portrepShift_nonprofes.xml"
ActiveWorkbook.XmlMaps("report_output_shftProfes_BMA").Import URL:= _
"Q:\Summit\Professional\portrepShift_BMA_profes.xml"
ActiveWorkbook.XmlMaps("report_output_shftProfes_Libor").Import URL:= _
"Q:\Summit\Professional\portrepShift_profes.xml"
ActiveWorkbook.XmlMaps("report_output_MtM").Import URL:= _
"Q:\Summit\Professional\portrep_MtM_allcpty.xml"
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
One way is to concatenate the date extension to the file name.
Code:
ActiveWorkbook.XmlMaps("report_output_Pv01").Import URL:= _
"Q:\Summit\Professional\ALPTOTAL_RC_PORTBPV_" & Format(2/26/2013, "yyyymmdd") & ".xml"
 
Upvote 0
Hello JLGwhiz,
Wouldnt this require me to change the date for all files each time I pick a different date? Is there a way to declare a variable for the date so all i have to do is type a date in a cell where this variable will read? Can you please clarify? Thank you.
 
Upvote 0
Yes, but it is the same code, just change the date in the code to a cell reference, for example cell A2 on Sheet1:
Code:
ActiveWorkbook.XmlMaps("report_output_Pv01").Import URL:= _
"Q:\Summit\Professional\ALPTOTAL_RC_PORTBPV_" & Format(Sheets("Sheet1").Range("A2").Value, "yyyymmdd") & ".xml"
Or using a variable
Code:
Dim myVal As Date
myVal = Sheets("Sheet1").Range("A2").Value
ActiveWorkbook.XmlMaps("report_output_Pv01").Import URL:= _
"Q:\Summit\Professional\ALPTOTAL_RC_PORTBPV_" & Format(myVal, "yyyymmdd") & ".xml"
 
Upvote 0
Hello,
I tried your suggestions above but in both cases I get this run time error shown below. I'm not sure whether the error occurs on the first line where importing happens or on the 2nd line where the concatenation happens. The target file is highlighted below. Do I have to declare the path which I think I dont have since the patch is already specified in this line. I suspect this code results in a concatenated filename of "Q:\Summit\Professional\ALPTOTAL_RC_PORTBPV_20130327.xml" which I think may be the cause of the problem. The concatenated filename must be the same as the one shown in the screenshot below. Please help. Thank you.




-- removed inline image ---

-- removed inline image ---
 
Upvote 0
Hello JLGWhiz,

I tried your suggestion and the code is below. I am getting error "Run-time error '-2147217376 (80041020)': XML Parse Error
I highlighted below where the code encounters the error. The value in Sheets("DashBoard").Range("S5") is 4/5/2013.
I have no success debugging this problem. Can you please help. Thank you very much.



Sub HistQuery()

Dim myVal As Date
myVal = Sheets("DashBoard").Range("S5").Value
ActiveWorkbook.XmlMaps("report_output_Pv01").Import URL:= _
"Q:\Summit\Professional\ALPTOTAL_RC_PORTBPV_" & Format(myVal, "yyyymmdd") & ".xml"





End Sub
 
Upvote 0

Forum statistics

Threads
1,214,615
Messages
6,120,538
Members
448,970
Latest member
kennimack

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