+ Reply to Thread
Results 1 to 4 of 4

Import data from unknown workbook name

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-12-2018
    Location
    Clearwater, FL
    MS-Off Ver
    MS 365
    Posts
    217

    Import data from unknown workbook name

    I have this code which a report is generated and it is not a constant name except the beginning of the file name which is "_ttv-".
    Sub wbName()
        Dim wb As Workbook
        Const wbName As String = "_ttv-"
    
    ThisWorkbook.Sheets("IEX Data - CT Set 20").Cells.ClearContents
    
        For Each wb In Application.Workbooks
            If wb.Name Like wbName & "*" Then
                
                With wb.Sheets("Intraday")
                    Sheets("Intraday").Cells.Copy
                    With Worksheets("IEX Data - CT Set 20")
            .Paste Destination:=.Range("A1")
        End With
        Application.CutCopyMode = False
            Application.DisplayAlerts = False
        Sheets("Intraday").Delete
        Application.DisplayAlerts = True 'New line
                End With
            End If
        Next wb
    End Sub
    Its not pulling the data like I need it to. The workbooks name always changes after I generate it - after it copies that data over, I would like the "_ttv-" workbook to close. Any help would be greatly appreciated! Thank you in advance!

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Import data from unknown workbook name

    Its not pulling the data like I need it to.
    This tells me nothing that I can use to fix it.

    The workbooks name always changes after I generate it
    Is this a problem, or just a statement of fact?

    I would like the "_ttv-" workbook to close
    If you want to save the workbook then
    wb.Cloxe True
    If Not then
    wb.Close False
    Place this statement before the 'Next wb' statement.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,741

    Re: Import data from unknown workbook name

    How about
    Sub wbName()
        Dim wb As Workbook
        Const wbName As String = "_ttv-"
    
    ThisWorkbook.Sheets("IEX Data - CT Set 20").Cells.ClearContents
    
       For Each wb In Application.Workbooks
          If wb.Name Like wbName & "*" Then
             
             With wb.Sheets("Intraday")
                .Cells.Copy
                ThisWorkbook.Worksheets("IEX Data - CT Set 20").Range("A1").PasteSpecial xlPasteValues
                Application.CutCopyMode = False
                Application.DisplayAlerts = False
                .Delete
                Application.DisplayAlerts = True 'New line
             End With
             
          End If
          wb.Close True
       Next wb
    End Sub
    This will save the _ttv workbook

  4. #4
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,086

    Re: Import data from unknown workbook name

    What makes the difference with your previous thread

    https://www.excelforum.com/excel-pro...3-import-data-

    A remake with file closing ...!

    
    Option Explicit
    Sub wbName()
    Dim wb As Workbook
    Const wbName As String = "_ttv-"
    Const DstWsName As String = "IEX Data - CT Set 20"
    Const OrgWsName As String = "Intraday"
    
        ThisWorkbook.Sheets(DstWsName).Cells.ClearContents
        For Each wb In Application.Workbooks
            If wb.Name Like wbName & "*" Then
                wb.Sheets(OrgWsName).Cells.Copy _
                    Destination:=ThisWorkbook.Worksheets(DstWsName).Range("A1")
                Application.CutCopyMode = False
                wb.Close SaveChanges:=False
            End If
    
        Next wb
    End Sub
    Last edited by PCI; 05-21-2018 at 04:42 PM.
    - Battle without fear gives no glory - Just try

+ 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. Import data to a workbook from another workbook with relative path
    By kexet77 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-19-2015, 08:03 AM
  2. Can I have Excel search another workbook for data and import it to my current workbook?
    By mgruber in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 0
    Last Post: 09-05-2014, 07:13 PM
  3. Replies: 0
    Last Post: 03-27-2014, 12:38 PM
  4. [SOLVED] Import data from an excel workbook to another workbook without manually selecting
    By rmachbitz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-15-2013, 02:27 PM
  5. Replies: 1
    Last Post: 11-26-2011, 09:10 PM
  6. Collecting Data from multiple sheets of a workbook and import them into new workbook
    By tufanayd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-16-2009, 04:10 PM
  7. [SOLVED] Import/Copy some data from one workbook to a similar workbook
    By dmbluv@comcast.net in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-07-2006, 08:40 AM

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