Last edited by Leith Ross; 03-14-2014 at 05:01 PM.
Hi..
Try this.. change the file path to suit..
or this with a File Browser Dialogue..Sub Test() Dim x x = Split(CreateObject("scripting.filesystemobject").opentextfile("C:\HELP.txt").readall, vbCrLf) Sheets("Original").Range("A1").Resize(UBound(x)).Value = Application.Transpose(x) End Sub
Sub Test1() Dim x, fName fName = Application.GetOpenFilename("Text Files (*.txt),*.txt") If fName <> "False" Then x = Split(CreateObject("scripting.filesystemobject").opentextfile(fName).readall, vbCrLf) Sheets("Original").Range("A1").Resize(UBound(x)).Value = Application.Transpose(x) End If End Sub
Last edited by apo; 03-14-2014 at 07:39 PM.
Try change
toSet sht = wb.Worksheets("Sheet1")
Set sht = wb.Worksheets(1)
The final code is:
But how can I mod so if they cancel and dont load any file, it will prompt a message saying, you did not select any file?Sub Open_File() Dim wb As excel.Workbook Dim wsActive As excel.Worksheet Dim sht As excel.Worksheet Dim f As Object Set wsActive = ActiveSheet Set f = Application.FileDialog(3) f.AllowMultiSelect = False f.Show Set wb = Workbooks.Open(f.SelectedItems(1)) Set sht = wb.Worksheets(1) wsActive.UsedRange.ClearContents LR = sht.UsedRange.SpecialCells(xlLastCell, xlNumbers).Row sht.Range("A1:L" & LR).Copy wsActive.Range("A1").PasteSpecial Paste:=xlPasteValues Application.CutCopyMode = False wb.Close False End Sub
Thanks.
Try change
tof.Show
If Not f.Show Then MsgBox "you did not select any file?" Exit Sub End If
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks