Open an excel file and automatically attach a specific sheet to it from another file.

tvagge

New Member
Joined
Nov 16, 2016
Messages
34
Hi guys,

This is maybe a little bit extreme and off-topic (!)....
Is there a way when I open an excel file named "db*****" (e.g db12525, db25658, db98745, etc), a specific sheet (named "calc" from another file named calculate.xls) to be attached to the opened file automatically ?
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Sektor

Well-known Member
Joined
May 6, 2011
Messages
2,874
Office Version
  1. 365
Platform
  1. Windows
In Workbook's module (ThisWorkbook):
Code:
Private Sub Workbook_Open()
    Dim wkbCalc As Workbook
    Set wkbCalc = Workbooks.Open("FULL_PATH_TO_CALC_WORKBOOK")
    wkbCalc.Sheets("calc").Copy ThisWorkbook.Sheets(1)
    wkbCalc.Close False
End Sub
 
Upvote 0

tvagge

New Member
Joined
Nov 16, 2016
Messages
34
Wow! That was fast!

I didn't get it to work...
Let me explain again:
I have multiple files named like "db*****". These files are created by a database, with different file name everytime.
I want everytime I open these kind of files (and trust me, these files are many...), a specific sheet named "calc" from a specific xlsm file named "calculate.xlsm" to be attached to the file I open automatically.
E.g:
When I open the file named "db12345.xls", the sheet "calc" automatically to be attached to it.
When I open the file named "db12222.xls", the sheet "calc" automatically to be attached to it.
When I open the file named "db13212.xls", the sheet "calc" automatically to be attached to it.

etc...
 
Upvote 0

Sektor

Well-known Member
Joined
May 6, 2011
Messages
2,874
Office Version
  1. 365
Platform
  1. Windows
I see. You won't be able to this manually because macros must exists in those db*** workbooks.
To make it happen, you must programmatically (i.e. from macros in root workbook) open those db** files.
 
Upvote 0

Forum statistics

Threads
1,191,689
Messages
5,988,032
Members
440,125
Latest member
vincentchu2369

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top