madhuchelliah
Board Regular
- Joined
- Nov 22, 2017
- Messages
- 226
- Office Version
- 2019
- Platform
- Windows
Hello guys, i am importing data from a XML file. The contents are consists of Alpha, numeric and symbols. After importing, the cell formats are showing as General. Some of my values are like Date and Time format. After pasting, Date like values changed to 8 digit number and some Time like values showing with AM or PM suffixes. I want to keep the values as it is. How to do that using macro? The code below shown is i am using for importing. Thank you.
Code:
Sub Import()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim ws As Worksheet
Dim PasteStart As Range
Dim FileToOpen As String
Set wb1 = ActiveWorkbook
Set PasteStart = [Sheet2!C2]
'Sheets("Sheet2").Cells.ClearContents
Dim FileName As String
Dim folderPath As String
folderPath = "C:\"
FileName = folderPath & ThisWorkbook.Worksheets("Sheet1").Range("E4").Value & ".xml"
FileToOpen = FileName _
Set wb2 = Workbooks.Open(FileName:=FileToOpen)
For Each ws In wb2.Worksheets
If ws.Range("E1") = "" Then ws.Columns("E").Delete
With ws.UsedRange
.Copy PasteStart
Set PasteStart = PasteStart.Offset(.Rows.Count)
End With
Next ws
wb2.Close False
End Sub
Last edited: