+ Reply to Thread
Results 1 to 2 of 2

Using VBA to open a closed excel file

  1. #1
    Registered User
    Join Date
    04-12-2019
    Location
    Dallas
    MS-Off Ver
    2016
    Posts
    64

    Using VBA to open a closed excel file

    I am trying to make a function that will gather 4 strings that will end up displaying a value from another excel worksheet that is closed. When I use the function I get the return #VALUE! is there something that I'm missing?

    Public Function GetValueFromClosedWorkbook(path, file, sheet, ref)
    Dim arg As String
    ' Let's check whether the file exists
    If Right(path, 1) <> "\" Then path = path & "\"
    If Dir(path & file) = "" Then
    GetValueFromClosedWorkbook = "File Not Found"
    Exit Function
    End If
    ' We create the argument
    arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
    Range(ref).Range("I12").Address(, , xlR1C1)
    'MsgBox arg
    ' Now we execute an XLM macro
    'All references must be given as R1C1 strings.
    GetValueFromClosedWorkbook = ExecuteExcel4Macro(arg)
    End Function

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Using VBA to open a closed excel file

    Works fine for me like this.
    Please Login or Register  to view this content.
    PS: Please use Code Tags when posting code. It makes your code much easier to read and copy for testing, and it also maintains VBA formatting.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

+ 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. How to copy a cell from a closed excel file to another open excel file
    By anup_keshri in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 12-22-2013, 08:48 AM
  2. [SOLVED] strange sumifs problem, works with file open, #value with file closed
    By neowok in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-04-2013, 05:32 AM
  3. Open file after workbook executing code is closed
    By randell.graybill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2011, 10:05 PM
  4. Check if file is open and open if closed
    By Jockster in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-22-2010, 08:18 AM
  5. automatically open a file with excel closed
    By juanjose in forum Excel General
    Replies: 2
    Last Post: 08-26-2009, 12:07 PM
  6. open a file automatically at a time if excel is closed
    By juanjose in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-26-2009, 11:27 AM
  7. VBAProject remains open after file is closed
    By sequoia sam in forum Excel General
    Replies: 4
    Last Post: 08-02-2005, 03:05 PM
  8. [SOLVED] Use ADO to transfer data from open excel file to closed excel file
    By JCanyoneer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2005, 03:06 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