I have a macro that works if I open the file using GetOpenFilename and select the file from the open dialog box (the macro copies the last row of data in the open worksheet and copies to the launch worksheet). But the macro stops just after opening the other workbook if I hard code the file name or read the filename from a cell. I wonder if anyone can help. No error message.

Code below is the working version, I am able open the file called filetoOpen. Just below this code is the commented out code to read the same filename from a cell in the worksheet, or commented out direct text loading of filetoOpen. I have confirmed through message boxes that I am reading in or hard coding the name correctly, and the file does indeed open. Again the macro appears to have finished or stopped, does not execute any steps below the file open step if I read the name or hard code the name (the "test" message is never delivered).

In the end I want to read the file name to open from the worksheet I am in from the cell. I have tried several methods of opening the file (they are commented out in the code) and they all work with the GetOpenFilename code and none work with reading the file or hard coding. The file indeed is a tab delimited text file which I name as .xls name.

I would appreciate any help.

Sub Fileopen()
'

' Open text file, copy last row and paste into the spot where I started
Dim rng As Range
Dim iLastRow As Integer
Dim iLastCol As Integer
Dim filetoOpen As String
'Dim filetoOpen As Workbooks
Dim FileNumber1 As Long
Dim FileNumber2 As Long
Dim FileNumber3 As Long
Dim f, fs
Dim wkbcnt
Dim wbOpen As Workbook
Static WB As Workbook
Static WS As Worksheet
Static R As Range

'Application.DisplayAlerts = False

'Record the current location, exact row where we wish to paste copied row
Set WB = ActiveWorkbook
Set WS = ActiveSheet
Set R = Selection
'Dim DataToBeCopied As Variant

'Next open the text file directly. Dialog window opens and the rest of the macro will work fine

filetoOpen = Application _
.GetOpenFilename("All Files (*.*), *.*")

' Neither of these code segments will work (comment out the GetOpenFilename code above. The file opens but then the macro just
stops

'filetoOpen = Range("A12")
'filetoOpen = "..\170C 12s 4MPa\070201 170C 12s 4MPa Cycle S1 B62.xls"

MsgBox filetoOpen

'Now actually open the file.

Workbooks.OpenText Filename:= _
filetoOpen

' I have tried several variations on opening the file, all work with the 
' GetFileOpen method and non work with the other two ways
' Workbooks.OpenText filetoOpen 
'Workbooks.Open Filename:=filetoOpen 
'Workbooks.Open filetoOpen,

MsgBox "test"
'This message box is not executed if I use the other two methods, works fine
'with the GetFileOpen dialog box methods


'This code opens a text file as an Excel Workbook

' Determine the last row in the open file
Set rng = Range("A1").SpecialCells(xlCellTypeLastCell)
iLastRow = rng.Row
iLastCol = rng.Column

' MsgBox iLastRow
' iLastRow = filetoOpen.Cells(Rows.Count, "A").End(xlUp).Row

Rows(iLastRow).Select

    Application.CutCopyMode = False
    Selection.Copy
    
'Move back to starting location and paste
    WB.Activate
    WS.Activate
    R.Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Application.CutCopyMode = False

wkbcnt = Workbooks.Count
'Get the number of total workbooks open

Workbooks(wkbcnt).Close SaveChanges:=True
'Close the highest numbered workbook that is open, it will be the one we just
'read from, other workbooks will stay open. SaveChanges prevents dialog box
'about a large selection in the clipboard

End Sub