VBA code stops executing after the Workbooks.Open method executes in Excel 2010

I have an Excel 2010 xlsm file that is going to open another workbook and work with data from it.  Currently the other file I have been playing with is an xlsx.  My code looks like this:

Sub MainRoutine()

Dim strDataFile As String

strDataFile = OpenFile()


End Sub

Function OpenFile() As String

Dim strFileName
Dim wb As Workbook
Dim Name2 As String

ChDrive "S"
ChDir "\_ Log Merch Optimizing\Rich Frazer RTL solutions"
strFileName = Application.GetOpenFilename("Excel 2010 Files (*.xlsx),*.xlsx")
Debug.Print strFileName
If strFileName = "False" Then
    Exit Function
End If
Set wb = Workbooks.Open(Filename:=strFileName)
OpenFile = ActiveWorkbook.Name
Debug.Print Name2

End Function

Open in new window


However as soon as the Workbooks.Open occurs, the other workbook opens, but my code stops executing.  I've opened other workbooks with VBA in several projects and I don't remember this happening before (if it did it was when I was working with Excel 97 and I have no hope of remembering back that far).

Any insight Experts?
StudmillGuyAsked:
Who is Participating?
 
Martin LissConnect With a Mentor Older than dirtCommented:
Try adding Thisworkbook.Activate between lines 24 and 25. Where does Name2 come from?
0
 
StudmillGuyAuthor Commented:
Name2 was just a leftover from some prior troubleshooting I was doing.  Thisworkbook.Activate did the trick.  Thanks.
0
 
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0
 
StudmillGuyAuthor Commented:
To anyone stumbling on the thread, did I put this question in the right category?  What could I have done to make it easier to find (and make it easier for another user to find this answer)?
0
All Courses

From novice to tech pro — start learning today.