ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Yet another "copy method of worksheet class failed" (https://www.excelbanter.com/excel-programming/363032-yet-another-copy-method-worksheet-class-failed.html)

[email protected]

Yet another "copy method of worksheet class failed"
 
I am creating a macro to copy worksheets from an external workbook to
the current active workbook. I am receiving the error mentioned in the
subject.

The code snippet is here.

Shown is the active workbook and another workbook (templates are
standard workbooks). If the sheet count is greater than three (filled
sheet of data) the I want to copy in the full sheets that have that
data. The first two sheets are notes sheets so they are not of value
in this spreadsheet.

I am able to communicate with both sheets but unable to perform the
copy. The copy fails on the FIRST pass - always.

All help is appreciated.

Thanks,
pdr

Dim vSheet As Worksheet
Dim CurrentTemplateWorkbook As Workbook
Dim Test_ConfigTemp As Workbook
Set Test_ConfigTemp = Excel.ActiveWorkbook

Set xlApp = CreateObject("Excel.Application")
Set CurrentTemplateWorkbook =
xlApp.Workbooks.Open(ActiveWorkbook.Path & "\Templates\" &
pWorkBookName & ".xls")

If CurrentTemplateWorkbook.Sheets.Count 3 Then
Do While vMoveSheets <= CurrentTemplateWorkbook.Sheets.Count -
3
Set vSheet = CurrentTemplateWorkbook.Worksheets(vMoveSheets
+ 2)
MsgBox (vSheet.Name) 'check sheet name
CurrentTemplateWorkbook.Worksheets(vSheet.Name).Co py
after:=Test_ConfigTemp.Worksheets(Test_ConfigTemp. Sheets.Count)
vMoveSheets = vMoveSheets + 1
Loop
End If


[email protected]

Yet another "copy method of worksheet class failed"
 
PS: If any option would be better then I would entertain that as well.
pdr

wrote:
I am creating a macro to copy worksheets from an external workbook to
the current active workbook. I am receiving the error mentioned in the
subject.

The code snippet is here.

Shown is the active workbook and another workbook (templates are
standard workbooks). If the sheet count is greater than three (filled
sheet of data) the I want to copy in the full sheets that have that
data. The first two sheets are notes sheets so they are not of value
in this spreadsheet.

I am able to communicate with both sheets but unable to perform the
copy. The copy fails on the FIRST pass - always.

All help is appreciated.

Thanks,
pdr

Dim vSheet As Worksheet
Dim CurrentTemplateWorkbook As Workbook
Dim Test_ConfigTemp As Workbook
Set Test_ConfigTemp = Excel.ActiveWorkbook

Set xlApp = CreateObject("Excel.Application")
Set CurrentTemplateWorkbook =
xlApp.Workbooks.Open(ActiveWorkbook.Path & "\Templates\" &
pWorkBookName & ".xls")

If CurrentTemplateWorkbook.Sheets.Count 3 Then
Do While vMoveSheets <= CurrentTemplateWorkbook.Sheets.Count -
3
Set vSheet = CurrentTemplateWorkbook.Worksheets(vMoveSheets
+ 2)
MsgBox (vSheet.Name) 'check sheet name
CurrentTemplateWorkbook.Worksheets(vSheet.Name).Co py
after:=Test_ConfigTemp.Worksheets(Test_ConfigTemp. Sheets.Count)
vMoveSheets = vMoveSheets + 1
Loop
End If



Matt Lunn[_3_]

Yet another "copy method of worksheet class failed"
 


" wrote:

I am creating a macro to copy worksheets from an external workbook to
the current active workbook. I am receiving the error mentioned in the
subject.

The code snippet is here.

Shown is the active workbook and another workbook (templates are
standard workbooks). If the sheet count is greater than three (filled
sheet of data) the I want to copy in the full sheets that have that
data. The first two sheets are notes sheets so they are not of value
in this spreadsheet.

I am able to communicate with both sheets but unable to perform the
copy. The copy fails on the FIRST pass - always.

All help is appreciated.

Thanks,
pdr

Dim vSheet As Worksheet
Dim CurrentTemplateWorkbook As Workbook
Dim Test_ConfigTemp As Workbook
Set Test_ConfigTemp = Excel.ActiveWorkbook

Set xlApp = CreateObject("Excel.Application")
Set CurrentTemplateWorkbook =
xlApp.Workbooks.Open(ActiveWorkbook.Path & "\Templates\" &
pWorkBookName & ".xls")

If CurrentTemplateWorkbook.Sheets.Count 3 Then
Do While vMoveSheets <= CurrentTemplateWorkbook.Sheets.Count -
3
Set vSheet = CurrentTemplateWorkbook.Worksheets(vMoveSheets
+ 2)
MsgBox (vSheet.Name) 'check sheet name
CurrentTemplateWorkbook.Worksheets(vSheet.Name).Co py
after:=Test_ConfigTemp.Worksheets(Test_ConfigTemp. Sheets.Count)
vMoveSheets = vMoveSheets + 1
Loop
End If



Which line does the code stop at?

[email protected]

Yet another "copy method of worksheet class failed"
 
The line it stops at is the copy line -
CurrentTemplateWorkbook.Worksheets(vSheet.Name).Co py
after:=Test_ConfigTemp.Worksheets(Test_ConfigTemp. Sheets.Count)
with the error.

I have tried to perform a range copy with similar results. For some
reason I cannot get the copy to copy the sheet either into the current
workbook or ideally into a separate external workbook. My goal is to
take worksheets from multiple workbooks and compile them into a single
workbook for review and documentation.

pdr

Matt Lunn wrote:
" wrote:

I am creating a macro to copy worksheets from an external workbook to
the current active workbook. I am receiving the error mentioned in the
subject.

The code snippet is here.

Shown is the active workbook and another workbook (templates are
standard workbooks). If the sheet count is greater than three (filled
sheet of data) the I want to copy in the full sheets that have that
data. The first two sheets are notes sheets so they are not of value
in this spreadsheet.

I am able to communicate with both sheets but unable to perform the
copy. The copy fails on the FIRST pass - always.

All help is appreciated.

Thanks,
pdr

Dim vSheet As Worksheet
Dim CurrentTemplateWorkbook As Workbook
Dim Test_ConfigTemp As Workbook
Set Test_ConfigTemp = Excel.ActiveWorkbook

Set xlApp = CreateObject("Excel.Application")
Set CurrentTemplateWorkbook =
xlApp.Workbooks.Open(ActiveWorkbook.Path & "\Templates\" &
pWorkBookName & ".xls")

If CurrentTemplateWorkbook.Sheets.Count 3 Then
Do While vMoveSheets <= CurrentTemplateWorkbook.Sheets.Count -
3
Set vSheet = CurrentTemplateWorkbook.Worksheets(vMoveSheets
+ 2)
MsgBox (vSheet.Name) 'check sheet name
CurrentTemplateWorkbook.Worksheets(vSheet.Name).Co py
after:=Test_ConfigTemp.Worksheets(Test_ConfigTemp. Sheets.Count)
vMoveSheets = vMoveSheets + 1
Loop
End If



Which line does the code stop at?



[email protected]

Yet another "copy method of worksheet class failed"
 
I have solved the issue of the range copy not working. What I needed
to do was perform it at the worksheet level but not as I understood it.
As oppose to doing it WorkBook.WorkSheet(index).Range().copy, I needed
to define a worksheet variable as follows:
Dim wstWorkSheet as WorkSheet
wstWorkSheet.Range("A:Z").Copy

I still have not been able to do a direct copy of worksheets between
two external workbooks.
Ex:
Open workbook1 (controling workbook for management) and identify
workbooks to be manipulated/tracked. Once identified merge all
identified workbooks into a master workbook for reporting.
Workbook1 creates workbook2 for merging. Next workbook1 opens the
identified workbooks and copies the data worksheets (typically
worksheet 3 - specially named) from the identified worksheets to
workbook2 (merging workbook). Worksheets are tracked to ensure no
duplicates.

All aid is appreciated.

Thanks,
pdr

wrote:
The line it stops at is the copy line -
CurrentTemplateWorkbook.Worksheets(vSheet.Name).Co py
after:=Test_ConfigTemp.Worksheets(Test_ConfigTemp. Sheets.Count)
with the error.

I have tried to perform a range copy with similar results. For some
reason I cannot get the copy to copy the sheet either into the current
workbook or ideally into a separate external workbook. My goal is to
take worksheets from multiple workbooks and compile them into a single
workbook for review and documentation.

pdr

Matt Lunn wrote:
" wrote:

I am creating a macro to copy worksheets from an external workbook to
the current active workbook. I am receiving the error mentioned in the
subject.

The code snippet is here.

Shown is the active workbook and another workbook (templates are
standard workbooks). If the sheet count is greater than three (filled
sheet of data) the I want to copy in the full sheets that have that
data. The first two sheets are notes sheets so they are not of value
in this spreadsheet.

I am able to communicate with both sheets but unable to perform the
copy. The copy fails on the FIRST pass - always.

All help is appreciated.

Thanks,
pdr

Dim vSheet As Worksheet
Dim CurrentTemplateWorkbook As Workbook
Dim Test_ConfigTemp As Workbook
Set Test_ConfigTemp = Excel.ActiveWorkbook

Set xlApp = CreateObject("Excel.Application")
Set CurrentTemplateWorkbook =
xlApp.Workbooks.Open(ActiveWorkbook.Path & "\Templates\" &
pWorkBookName & ".xls")

If CurrentTemplateWorkbook.Sheets.Count 3 Then
Do While vMoveSheets <= CurrentTemplateWorkbook.Sheets.Count -
3
Set vSheet = CurrentTemplateWorkbook.Worksheets(vMoveSheets
+ 2)
MsgBox (vSheet.Name) 'check sheet name
CurrentTemplateWorkbook.Worksheets(vSheet.Name).Co py
after:=Test_ConfigTemp.Worksheets(Test_ConfigTemp. Sheets.Count)
vMoveSheets = vMoveSheets + 1
Loop
End If



Which line does the code stop at?




All times are GMT +1. The time now is 06:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com