![]() |
Import sheet error
Hi
I am trying to use the below code to import a title page for my reports but it is coming with the error message: 'Compile error: Object error' On line 'Set CurrWb = ActiveWorkbook.Name' Can anyone help resolve this? TIA Sub AddTitlePage() Dim CurrWb As String Dim TitleWb As Workbook Set CurrWb = ActiveWorkbook.Name Set TitleWb = Workbooks.Open("F:\Resources\Title Page.xls") With TitleWb ..Sheets("Title").Copy Befo=Workbooks(CurrWb).Sheets(1) ..Close End With End Sub |
Import sheet error
Edgar,
As a general rule, unless you are assigning an object, you don't need a Set statement. i.e. CurrWb = ActiveWorkbook.Name But, you could do the whole thing without the use of the String, e.g. Sub AddTitlePage() Dim CurrWb As WORKBOOK Dim TitleWb As Workbook Set CurrWb = ActiveWorkbook Set TitleWb = Workbooks.Open("F:\Resources\Title Page.xls") With TitleWb ..Sheets("Title").Copy Befo=CurrWb.Sheets(1) ..Close End With End Sub Robin Hammond www.enhanceddatasystems.com "Edgar Thoemmes" wrote in message ... Hi I am trying to use the below code to import a title page for my reports but it is coming with the error message: 'Compile error: Object error' On line 'Set CurrWb = ActiveWorkbook.Name' Can anyone help resolve this? TIA Sub AddTitlePage() Dim CurrWb As String Dim TitleWb As Workbook Set CurrWb = ActiveWorkbook.Name Set TitleWb = Workbooks.Open("F:\Resources\Title Page.xls") With TitleWb .Sheets("Title").Copy Befo=Workbooks(CurrWb).Sheets(1) .Close End With End Sub |
All times are GMT +1. The time now is 12:22 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com