+ Reply to Thread
Results 1 to 3 of 3

Copy filename of source workbook to specific cell in specific tab in destination workbook.

Hybrid View

MagicMan Copy filename of source... 03-28-2015, 09:58 PM
p24leclerc Re: Copy filename of source... 03-28-2015, 10:12 PM
MagicMan Re: Copy filename of source... 03-28-2015, 10:29 PM
  1. #1
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    447

    Question Copy filename of source workbook to specific cell in specific tab in destination workbook.

    HI Guys,

    Thanks to mikeTRON, I've got a macro to copy all the tabs in from another workbook which is achieved by navigating to that workbook (see below). However, I forgot to ask for a code that does the will take the filename of the source workbook (without the extension) and put it into cell C2 of the "Welcome" tab in the destination workbook.

    Can anyone help please?

    Thanks


    Sub ImportSheets()
    
        'Declare Vaiables
            Dim filePathandName As Variant
            Dim filename As String
            Dim sheet As Worksheet
            Dim total As Integer
        
        'Setup VBA for SPEED
            Application.ScreenUpdating = False
            Application.DisplayAlerts = False
        
        'Define File and path
            filePathandName = Application.GetOpenFilename("Excel Files (*.xl*), *.xl*", Title:="************  Select File to Import  ************")
            
            If filePathandName <> False Then
            
                Workbooks.Open (filePathandName)
                filename = ActiveWorkbook.Name
            
            'Do Work
                For Each sheet In Workbooks(filename).Worksheets
                    total = ThisWorkbook.Worksheets.Count
                    Workbooks(filename).Worksheets(sheet.Name).Copy _
                    after:=ThisWorkbook.Worksheets(total)
                Next sheet
            
            'Close the workbook
                Workbooks(filename).Close (False) 'Save the workbook without saving it
        
            End If
        
        'End Macro
            Application.ScreenUpdating = True
            Application.DisplayAlerts = True
        
    End Sub

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Copy filename of source workbook to specific cell in specific tab in destination workb

    you could add this line of code just before the "End IF" line
        Sheets("Welcome").Range("C2") = Left(filename, InStr(1, filename, ".xls", vbTextCompare) - 1)
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    447

    Re: Copy filename of source workbook to specific cell in specific tab in destination workb

    Just the ticket!! Thank you

+ 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. VBA Copy Paste Cuts From Source, Sends to Ether - Not To Destination Workbook
    By jcaynes in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2014, 11:05 AM
  2. Replies: 3
    Last Post: 07-11-2013, 03:01 AM
  3. How to move a workbook to a specific destination using VBA?
    By js1537 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-10-2013, 04:37 AM
  4. How do I post values from source workbook to destination workbook
    By Raghavendra Kulkarni in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-04-2005, 09:06 AM
  5. how to copy succeeding rows from source workbook to destination w.
    By chris in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-08-2005, 10: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