+ Reply to Thread
Results 1 to 4 of 4

get info from another excel file without opening it

  1. #1
    Registered User
    Join Date
    01-23-2015
    Location
    Ohio, USA
    MS-Off Ver
    2010
    Posts
    27

    get info from another excel file without opening it

    I can't quite figure this out.
    I want to run a macro the will:
    -display an open dialog box for xlsm files only
    -test if a value is TRUE in cell A1 of the chosen file without actually opening the file.
    Can this be done? Can I retrieve numerical values without opening as well?

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: get info from another excel file without opening it

    If the files are not locked you can use ADO to pull data from closed files.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: get info from another excel file without opening it

    This link perhaps?

    http://spreadsheetpage.com/index.php...a_closed_file/

    Alf

  4. #4
    Registered User
    Join Date
    01-23-2015
    Location
    Ohio, USA
    MS-Off Ver
    2010
    Posts
    27

    Re: get info from another excel file without opening it

    Thanks for the replies guys. I have seen many examples to do this but they all need user defined file paths (unless I'm overlooking something-new to VBA). I want the user to be able to choose what file, no matter the location and get/read data from a closed workbook without opening.

    This is what I have so far. New at VBA so there may be mistakes. Haven't tested:

    Private Sub AddWAA()
    Dim strFileToOpen As String
    Dim PromptCause As String
    Dim bError As Boolean

    bError = True
    'Use open prompt to choose a file to import data
    strFileToOpen = Application.GetOpenFilename _
    (Title:="Please select an WAA file to merge", _
    FileFilter:="Excel Files *.xlsm (*.xlsm),")
    'Checking if file is selected
    If strFileToOpen = False Then
    Exit Sub
    End If
    'Check named range data in closed WB without opening
    If Range("WAAFile") = False Then
    PromptCause = "The file you selected is not a WAA file."
    bError = False
    ElseIf Range("ReportGen") = False Then
    PromptCause = "The WAA file you selected has not generated a report yet."
    bError = False
    End If
    If bError = False Then
    MsgBox PromptCause, vbOKOnly, "WAA: Merge Error"
    Exit Sub
    End If
    'Transfer data from named range in closed WB and transfer to active WB
    Range("ClosedWAAFile") = Range("OpenWAAFile")
    MsgBox "Success", vbOKOnly, "Data merge"
    End Sub

+ 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. Replies: 2
    Last Post: 05-31-2014, 02:05 AM
  2. Replies: 3
    Last Post: 01-14-2014, 10:57 AM
  3. Replies: 4
    Last Post: 01-24-2012, 12:52 PM
  4. Opening EXCEL with a specific file opening also
    By HitTheEXCELerator in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-23-2011, 12:51 PM
  5. Replies: 1
    Last Post: 12-07-2005, 01:55 PM

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