Hi, I'm importing data using a piece of code as shown below. However, when it's imported (using "MasterProcedurePhaseOne") the data format is changed from dd/mm/yyyy to mm/dd/yyyy so it is incorrect. Can anyone advise how I make it work correctly? thanks, Neil
I've attached the file I am importing to (Importing File) and the one I am importing from (Data to Import).
The code I"m using is as follows:
Sub ImportData()
Dim Filt As String
Dim FilterIndex As Integer
Dim Title As String
Dim FileName As Variant 'Filename to be imported
Dim sourceWorkbook As Workbook 'source file
Dim targetWorkbook As Workbook 'Workbook to import data into (This one)
Dim targetSheet As Worksheet 'worksheet to import data into
Dim sourceSheet As Worksheet 'worksheet to import data from
Dim WSD As Worksheet
'---------------
'Assumption that active workbook is the target
Set targetWorkbook = Application.ActiveWorkbook
' Set up list of file filters
Filt = "Text Files (*.txt),*.txt," & _
"Lotus Files (*.prn),*.prn," & _
"Comma Separated Files (*.csv),*.csv," & _
"ASCII Files (*.asc),*.asc," & _
"All Files (*.*),*.*"
' Display *.* by default
FilterIndex = 5
' Set the dialog box caption
Title = "Select a File to Import"
' Get the file name
FileName = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Title)
' Exit if dialog box canceled
If FileName = False Then
MsgBox "No file was selected."
Exit Sub
End If
'-------------------
Set sourceWorkbook = Application.Workbooks.Open(FileName) 'workbook to get data from picked up from dialogue box
Set WSD = targetWorkbook.Worksheets("Data") 'assign sheet named "Data" into which to copy from expense file
Set sourceSheet = sourceWorkbook.Worksheets(1) 'Copy from first worksheet
'Copy in the Used range from the source sheet and put into the current workbook in worksheet "Data"
WSD.Range("A1:E" & Cells(Rows.Count, 1).End(xlUp).Row).Value = sourceSheet.UsedRange.Value
' Close expense workbook
sourceWorkbook.Close
End Sub
Bookmarks