Solved

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

Posted on 2013-10-29
4
2,927 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 47

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 47

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

752 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