0

First off, excuse my mistake if this has already been answered, but I was unable to find the solution to my question on Google and this site's search tool.

Language being used: Excel's VBA with VBA Editor

Statement of the problem: I would like to open up an existing Excel document as a new sheet within a currently opened Excel document. Currently my code looks something like this;

......
Dim myFile As String
myFile = Application.GetOpenFilename()
Dim oldWB as Workbook
oldWB = Application.Workbooks.Open(myFile)
.....

The results of the previous code, is a new Excel workbook being opened. This is close to what I am looking for, but I would like it to open up the document as a new sheet within the currently opened document.

  • 1
    You are going to have to make a new sheet and import the contents of a specific sheet of the file. You can't just open it directly as a new sheet since that's now how excel works. – chancea Dec 08 '14 at 17:04
  • Would you be kind enough to type pseudo code for me to see how I should go about tackling this? – Kurtis Schlienger Dec 08 '14 at 17:06

1 Answers1

0

You can use something like:

oldWB.Sheets.Add Type:="C:\Documents and Settings\user\Desktop\MyExcelFile.xls"

It's better if the file has ony a sheet

genespos
  • 3,211
  • 6
  • 38
  • 70
  • Thanks! This was almost perfect! Do you know how I can specify to only bring over "Sheet1" of the document? – Kurtis Schlienger Dec 08 '14 at 17:42
  • http://stackoverflow.com/questions/20246465/how-to-copy-only-a-single-worksheet-to-another-workbook-using-vba – user1274820 Dec 08 '14 at 17:42
  • In this case it's better you use the code in the link above, by opening the file with your code and then copying the sheet you need and finally closing the file – genespos Dec 08 '14 at 17:57