Results 1 to 3 of 3

Trying to activate an open Workbook with a variable

Threaded View

  1. #1
    Registered User
    Join Date
    01-22-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1

    Trying to activate an open Workbook with a variable

    Hi all,
    I have a script which opens a user-defined workbook, and later on I need to be able to activate that workbook. I have the filepath for the workbook defined, and I've been able to pull the filename from the path and store it as a variable. However, I get a Runtime Error '9': Subscript out of range notification whenever I try to activate the workbook using the variable I have set. Yet, when I copy and paste the variable contents into my Activate command, the script works.


    Dim fNameAndPath As Variant
    fNameAndPath = Application.GetOpenFilename(FileFilter:="All Files (*.), *.", Title:="Select File To Be Opened")
    If fNameAndPath = False Then Exit Sub
    Workbooks.Open fileName:=fNameAndPath
        'Dim filepath As String
        'filepath = fNameAndPath
           ' Title = Right(filepath, Len(filepath) - InStrRev(filepath, " \ "))
          Dim fso As New FileSystemObject
    Dim fileName As String
    fileName = fso.GetFileName(fNameAndPath)
    
        Windows("fileName").Activate
    Last edited by msf013; 01-22-2014 at 01:39 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How do I activate a workbook using a global variable?
    By Erikje in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-05-2013, 04:51 PM
  2. [SOLVED] Activate an open workbook
    By jimbolhp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-24-2012, 03:00 PM
  3. Activate Open Workbook
    By Launchnet in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-05-2010, 11:42 PM
  4. Need to activate an open workbook
    By TrafficGuy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-06-2008, 04:52 PM
  5. how to Activate the previous Open, workbook..?
    By acegap in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-25-2006, 11:20 AM

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