Open excel file into worksheet of open workbk [Solved/Closed]

hedles 2 Posts Saturday April 11, 2009Registration date April 12, 2009 Last seen - Apr 12, 2009 at 04:22 AM - Latest reply:  Fetzel
- Jul 23, 2010 at 03:47 PM

MS Excel 2000, VBA

I'd like to be able to open a file directly into a new worksheet of an open workbook, thus adding the new sheet in the process in a VBA macro.

I can open the file (which happens to be an html file, with that extension) fine into a new workbook, using the code:

Workbooks.Open Filename:="xxxxx.html"

However, I then have to copy and paste the contents of the worksheet in the newly opened workbook into the a new worksheet in the existing workbook.

If there is a way to open a file directly into a new worksheet of an open workbook it would be more efficient and save complications.
See more 

4 replies

Best answer
Excelguru 261 Posts Saturday April 11, 2009Registration date June 21, 2011 Last seen - Apr 12, 2009 at 06:34 AM
Thank you
The following code will copy the sheet2copy to the target workbook (as a new sheet)
Sheets(sheetname).copy after:=Workbooks(target workbookname).Sheets(1)

Thank you, Excelguru 9

Something to say? Add comment

CCM has helped 1781 users this month

Thanks Excelguru,

However, you don't appear to have read my question carefully. I wrote:

"I'd like to be able to open a file directly into a new worksheet of an open workbook".

I already know how to copy a worksheet from an open workbook to another workbook. I want to avoid this step altogether by opening the saved file directly into a sheet in the target workbook. This new sheet might need to be created separately first, or might be created by the same code that reads the external file into it. Something like,

Activeworkbook.worksheets(1).open filename:= "xxxx.html"

might do the job if it were available - however, the worksheet object does not have an 'open' method.

Serendipitously, only because the file I am loading from is an html file, I have now found a way to do this using

ActiveWorkbook.HTMLProject.HTMLProjectItems.Item("xxx").LoadFromFile ("yyy.html")

The negatives of this method are:
1. there is no 'add' method for the collection HTMLProjectItems, so I can only create more than one HTMLProjectItem (which I require) by a roundabout method and
2. I have not yet been able to find a way to prevent the annoying "refresh/don't refresh" dialogue from appearing every time I use the LoadFromFile method. Switching off alerts with,

Application.DisplayAlerts = False

does not work. Nor does switching off interactive mode with,

Application.Interactive = False

Any thoughts?
Thank you
I just figured this out! I copied my Template into 3 different directories (i.e. Drive\Program Files\Microsoft Office\Templates\1033 and 2 other that had pre-installed templates). Then I right-clicked on the sheet tab and selected "insert" and my template was there!! Hope this helps you...
Thank you
Private Sub Workbook_Open()
' put the sheet copy code here

End Sub