Search code examples
vbaexcelworksheet

Opening an existing Excel document as a new sheet


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.


Solution

  • 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