Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-10-29
4
Medium Priority
?
3,175 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 49

Accepted Solution

by:
Martin Liss earned 1000 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 49

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

783 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