Solved

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

Posted on 2013-10-29
4
2,771 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
  • 2
  • 2
4 Comments
 
LVL 45

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 45

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now