+ Reply to Thread
Results 1 to 16 of 16

Macro open file and go back

Hybrid View

  1. #1
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Macro open file and go back

    Welcome to the board!

    Please use code tags when posting code. Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    I would attempt to do something like this.
    Sub Open_File()
     Dim WBSrc As Workbook
     Dim WBDest As Workbook
     Dim sFil As String
     Dim sTitle As String
     Dim sWb As String
     Dim iFilterIndex As Integer
     On Error GoTo err_handler
     Set WBSrc = ThisWorkbook
     ' Set up list of file filters
     sFil = "Excel Files (*.xls),*.xls"
     ' Display *.xls by default
     iFilterIndex = 1
     ' Set the dialog box caption
     sTitle = "Select File to Zip"
     ' Get the filename
     sWb = Application.GetOpenFilename(sFil, iFilterIndex, sTitle)
     If sWb <> False Then
        Application.ScreenUpdating = False
        Set WBDest = Workbooks.Open(Filename:=sWb)
        WBSrc.Activate
        Application.ScreenUpdating = True
     End If
     Exit Sub
    err_handler:
     MsgBox "No selection made"
     
    End Sub
    This assigns your workbooks to variables so when you refer to them, you will always be assured that any references will be to the correct workbook. You don't have to worry which workbook is actually activated.
    David
    (*) Reputation points appreciated.

  2. #2
    Registered User
    Join Date
    09-04-2013
    Location
    Saskatoon, Canada
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Macro open file and go back

    Thanks for the code. When I run it, i am able to select a file, but it does not open and jumps right to "No selection made".

    Any thoughts?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro that prompts user to select a file to open and perform another macro on this file
    By grimmy26 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-16-2014, 08:39 AM
  2. [SOLVED] Macro - Master file to import data from another open file with variable file name
    By jdodz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2012, 10:56 PM
  3. Macro to save a back-up copy of a file when it's opened
    By Barking_Mad in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-16-2010, 02:30 PM
  4. Open a file do a macro ( made) and open next succesive file
    By SVTman74 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-21-2006, 05:20 PM
  5. Replies: 3
    Last Post: 02-09-2005, 08:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1