Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 18th, 2010, 04:13 AM
Registered User
 
Join Date: Aug 2010
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Shansur,

this is the line
oWS.Rows(1).EntireRow.Copy oCopy.Range("A1")

by the way actually wad i want is for me to determine the number of workbook
eg in a consist of 101 lines and a header
when i input 30 lines then it will create 4 new workbook
b consist of 2-30 lines
c next 31-60 lines
d next 61 - 90 lines
e remaining 91 - 100 lines

and each b,c,d,e will consist of the header from original workbook a. i want the data remain the same as it is in the original workbook a.

can help me out?
 
Old August 18th, 2010, 04:23 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Can you check it the objects (OWS and Ocopy) have some values

You can call

oWS.Range("A1").Copy oCopy.Range("A1")

and check if the values are OK
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old August 18th, 2010, 04:31 AM
Registered User
 
Join Date: Aug 2010
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Shasur,

it prompt me with the error "Copy method of Range class failed"

and it shows no value in the object

regards
 
Old August 18th, 2010, 04:45 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Can you post the full code so that I can test it

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old August 18th, 2010, 04:51 AM
Registered User
 
Join Date: Aug 2010
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Shasur,


Set xlApp = New Excel.Application
Set wb = xlApp.Workbooks.Open(txtFilepath.Text)



Dim oWS As Worksheet
Dim oWB As Workbook
Dim iMaxRow As Long
Dim iHalfRow As Long
Dim oCopy As Worksheet
Set oWS = wb.Worksheets(1)
iMaxRow = oWS.Cells.SpecialCells(xlCellTypeLastCell).Row
iHalfRow = iMaxRow / 2
Set oWB = Workbooks.Add
Set oCopy = oWB.Sheets(1)
oWS.Rows(1).EntireRow.Copy oCopy.Range("A1")
oWS.Range("A2", "Z" & CStr(iHalfRow)).EntireRow.Copy oCopy.Range("A2")
oWB.SaveAs "c:\Test\b.xls"
oWB.Close False
Set oWB = Workbooks.Add
Set oCopy = oWB.Sheets(1)
oWS.Rows(1).EntireRow.Copy oCopy.Range("A1")
oWS.Range("A" & CStr(iHalfRow + 1), "Z" & CStr(iMaxRow)).EntireRow.Copy oCopy.Range("A2")
oWB.SaveAs "c:\Test\c.xls"
oWB.Close False
 
Old August 19th, 2010, 12:50 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Can you try with this

Code:
Set xlApp = New Excel.Application
Set wb = xlApp.Workbooks.Open(txtFilepath.Text)

Dim oWS As Worksheet
Dim oWB As Workbook
Dim iMaxRow As Long
Dim iHalfRow As Long
Dim oCopy As Worksheet
Set oWS = wb.Worksheets(1)
iMaxRow = oWS.Cells.SpecialCells(xlCellTypeLastCell).Row
iHalfRow = iMaxRow / 2
Set oWB = xlApp.Workbook.Add
Set oCopy = oWB.Sheets(1)
oWS.Rows(1).EntireRow.Copy oCopy.Range("A1")
oWS.Range("A2", "Z" & CStr(iHalfRow)).EntireRow.Copy oCopy.Range("A2")
oWB.SaveAs "c:\Test\b.xls"
oWB.Close False
Set oWB = xlApp.Workbooks.Add
Set oCopy = oWB.Sheets(1)
oWS.Rows(1).EntireRow.Copy oCopy.Range("A1")
oWS.Range("A" & CStr(iHalfRow + 1), "Z" & CStr(iMaxRow)).EntireRow.Copy oCopy.Range("A2")
oWB.SaveAs "c:\Test\c.xls"
oWB.Close False
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old August 19th, 2010, 03:03 AM
Registered User
 
Join Date: Aug 2010
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Shasur,

The line below give me the error message. anything missing here?

Set oWB = xlApp.Workbook.Add <-----"object do not support this property or method"

here is my full code:

Code:
Dim xlApp As Excel.Application
Set xlApp = New Excel.Application
Set wb = xlApp.Workbooks.Open(txtFilepath.Text)
Dim oWS As Worksheet
Dim oWB As Workbook
Dim iMaxRow As Long
Dim iHalfRow As Long
Dim oCopy As Worksheet
Set oWS = wb.Worksheets(1)
iMaxRow = oWS.Cells.SpecialCells(xlCellTypeLastCell).Row
iHalfRow = iMaxRow / 2
Set oWB = xlApp.Workbook.Add
Set oCopy = oWB.Sheets(1)
oWS.Rows(1).EntireRow.Copy oCopy.Range("A1")
oWS.Range("A2", "Z" & CStr(iHalfRow)).EntireRow.Copy oCopy.Range("A2")
oWB.SaveAs "c:\Test\b.xls"
oWB.Close False
Set oWB = xlApp.Workbooks.Add
Set oCopy = oWB.Sheets(1)
oWS.Rows(1).EntireRow.Copy oCopy.Range("A1")
oWS.Range("A" & CStr(iHalfRow + 1), "Z" & CStr(iMaxRow)).EntireRow.Copy oCopy.Range("A2")
oWB.SaveAs "c:\Test\c.xls"
oWB.Close False
 
Old August 19th, 2010, 03:14 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Sorry it was a typo

It should be

oWB = xlApp.Workbooks.Add

Cheers
Shasur

__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)
 
Old August 19th, 2010, 03:50 AM
Registered User
 
Join Date: Aug 2010
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Shasur,

Still the same error after removing the

Set oWB = xlApp.Workbook.Add

to

oWB = xlApp.Workbook.Add
 
Old August 19th, 2010, 04:56 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

IT should be

Set oWB = oXlapp.Workbooks.add

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Edit Excel in VB6 Hornet28 VB How-To 6 December 9th, 2009 08:54 AM
VB6 Excel App to .NET problem zayasv VB.NET 0 October 24th, 2005 04:08 PM
VB6 Excel App to .NET problem zayasv General .NET 0 October 24th, 2005 04:05 PM
VB6/Excel/SQL tmiller1 Excel VBA 2 April 6th, 2005 02:10 PM
How can i open Excel From VB6 chiefouko Beginning VB 6 1 June 30th, 2003 08:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.