Solved

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

Posted on 2013-10-29
4
3,011 Views
Last Modified: 2013-10-29
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?
0
Comment
Question by:StudmillGuy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
Martin Liss earned 250 total points
ID: 39610061
Try adding Thisworkbook.Activate between lines 24 and 25. Where does Name2 come from?
0
 

Author Closing Comment

by:StudmillGuy
ID: 39610087
Name2 was just a leftover from some prior troubleshooting I was doing.  Thisworkbook.Activate did the trick.  Thanks.
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39610093
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0
 

Author Comment

by:StudmillGuy
ID: 39610102
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

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question