I have this code that pastes entire txt file contents to my active workbook but it loses leading “0” in cells:
Dim FileToOpen As Variant Dim OpenBook As Workbook FileToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt") If FileToOpen <> False Then Set OpenBook = Application.Workbooks.Open(FileToOpen) OpenBook.Sheets(1).UsedRange.Select Selection.NumberFormat = "@" OpenBook.Sheets(1).UsedRange.Copy ThisWorkbook.Worksheets("BOM").Range("C1").PasteSpecial xlPasteValues OpenBook.Close False End If
I tried to work around it by adding
OpenBook.Sheets(1).UsedRange.Select Selection.NumberFormat = "@"
But it doesn’t do the trick.
So how do I paste the contents and not lose leading “0”?