Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error when copying worksheet from 1 workbook to another

Status
Not open for further replies.

wlaflamme

Technical User
Aug 1, 2003
22
US
I have an VBA question concerning copying 1 worksheet to another workbook. The code that I have been testing works on my PC but when I go to other machines it fails calling an error.The error is :
"Run-Time Error '1004' Excel cannot insert the sheets into the destination workbook, because it contains fewer rows and columns than the source workbook.

Here is the code that I was using.
' Create a new workbook
Workbooks.Add

file_name = Application.InputBox("Enter the archived filename for current Measurement data", "Filename", Type:=2)
If file_name = "" Then
error1 = MsgBox("No file name entered. Data will not be archived. Please enter a valid filename")
Exit Sub
Else
Application.FileDialog(msoFileDialogFolderPicker).Show
MyPath = CurDir
MyPath = IIf(Right(MyPath, 1) = "\", MyPath, MyPath & "\")
ActiveWorkbook.SaveAs Filename:=MyPath & file_name & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
x = ActiveSheet.Name
'Copy the tabs "Purchase Order" and "Junk Board Labels"
Windows(file_name & ".xlsx").Activate
'Sheets("Junk Board Labels").Select
Workbooks("Purchase Order Template.xlsm").Sheets("Junk Board Labels").Copy , Before:=Workbooks(file_name & ".xlsx").Sheets(x)
'Sheets("Junk Board Labels").Copy Before:=Workbooks(file_name & ".xlsx").Sheets(x)
Windows(file_name & ".xlsx").Activate
'Sheets("Purchase Order").Select
'Sheets("Purchase Order").Copy Before:=Workbooks(file_name & ".xlsx").Sheets(x)
Workbooks("Purchase Order Template.xlsm").Sheets("Purchase Order").Copy , Before:=Workbooks(file_name & ".xlsx").Sheets(x)
Windows(file_name & ".xlsx").Activate
'Sheets("Addresses").Select
'Sheets("Addresses").Copy Before:=Workbooks(file_name & ".xlsx").Sheets(x)
Workbooks("Purchase Order Template.xlsm").Sheets("Addresses").Copy , Before:=Workbooks(file_name & ".xlsx").Sheets(x)


The error is in the following line of code:
Workbooks("Purchase Order Template.xlsm").Sheets("Junk Board Labels").Copy , Before:=Workbooks(file_name & ".xlsx").Sheets(x)
Any help would be apprecited. Thanks
 
All the machines have Excel 2007 ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes. They do. That is why it seems pretty weird.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top