Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old July 13th, 2006, 08:42 PM
teeheiman's Avatar
teeheiman teeheiman is offline
Let the Wookie Win
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Location: United States, Califonia
Posts: 190 teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 20 h 14 m 39 sec
Reputation Power: 17
Excel Application

Ive witten code to connect to my db and write out packing slips to an excel file, 1 packing slip to Each sheet. My problem is that the sheets are coming in as.
Sheet # | Packing Slip # | Arrangement in Exel
4 | 2 | 1
5 | 3 | 2
6 | 4 | 3
7 | 5 | 4
8 | 6 | 5
9 | 7 | 6
10 | 8 | 7
1 | 0 | 8
2 | 1 | 9
3 | 9 | 10

Instead of having Packing Slip 1 on Sheet 1 order 1 - 10, So it prints out the Pslips 1-10.

Is there a Sheet Move Function, and any reason why 9 is coming on the last page.

Heres my code:
Code:
strsheetcount = 1
xlrow = 1
master_file = "C:\Inetpub\WebSites\***\test.xls"
save_as_file = "C:\Inetpub\WebSites\***\output.xls"

Set xl = CreateObject("Excel.Application")
xl.Visible = False
xl.DisplayAlerts = False
xl.Interactive = False

Set wrk = xl.Workbooks.Open(master_file)
'Set wrkSht = wrk.sheets(1)		

		'Set to Sheet1 because that is excel default
	strsql = "Select * from tb_orders where status='Step 1'"
		rsitems.open strsql, adocon
	Do While Not Rsitems.EOF
		Set wrkSht = wrk.sheets(strsheetcount)
		stritemcount = 0
		

'-------------------------------------------------------------------------

		wrkSht.Cells(7, 1).Value = "#" & rsitems("order_ID")
		wrkSht.Cells(8, 1).Value = "Date:"
		wrkSht.Cells(9, 1).Value = "Ship to:"
		wrkSht.Cells(13, 1).Value = "Via:"
		wrkSht.Cells(15, 1).Value = "Item"
		wrkSht.Cells(15, 8).Value = "Code"
		wrkSht.Cells(15, 10).Value = "Qty"

		wrkSht.Cells(7, 3).Value = "Packing Slip" & rsitems("order_ID") & " for ***"
		wrkSht.Cells(8, 3).Value = now
		wrkSht.Cells(9, 3).Value = rsitems("s_firstname") & " " & rsitems("s_lastname")
		wrkSht.Cells(10, 3).Value = rsitems("s_address")
		wrkSht.Cells(11, 3).Value = rsitems("s_city") & " " & rsitems("s_state") & ", " & rsitems("s_zip")
		wrkSht.Cells(13, 3).Value = strshipping

	strsql2 = "Select * from tb_sold where order_id='" & rsitems("order_ID") & "'"
	rsitems2.open strsql2, adocon
	Do While Not Rsitems2.EOF
		
		wrkSht.Cells(16 + cint(stritemcount), 1).Value = rsitems2("Item_Name")
		wrkSht.Cells(17 + cint(stritemcount), 1).Value = "http://***/?itemnum=" & rsitems2("Item_ID")
		wrkSht.Cells(16 + cint(stritemcount), 8).Value = rsitems2("Item_ID")
		wrkSht.Cells(16 + cint(stritemcount), 10).Value = rsitems2("qty")
		stritemcount = stritemcount + 2
		
	rsitems2.movenext
	loop

		xlrow = xlrow + 1

	rsitems2.close
	rsitems.movenext
	If NOT rsItems.EOF then		'IF THERE IS ANOTHER RECORD, COPY/PASTE

		'----------------------------------------------------------------------------------------
		'	PASTE NEW SHEET
		'-----------------------------------------------------------------------------------------
		strsheetcount = strsheetcount + 1

		If strsheetcount > 3 Then
			wrk.sheets.add()
		End If

		'Set wrkSht = wrk.sheets("Sheet1")		'SELECT THE ORIGINAL
		wrk.sheets("Sheet1").Select
		wrkSht.Cells.Copy				'COPY CELLS FROM 1st

		Set wrkSht = wrk.sheets("Sheet" & strsheetcount)		'Set 2nd wrkSht object to sheet2
		'wrkSht.Cells.Select

		wrkSht.Paste			'Paste the copied text
		xl.CutCopyMode = False		'I have no idea what this means

	End If
loop

rsitems.close
adocon.close
set rsitems = nothing
set rsitems2 = nothing
set adocon = nothing


'----------------------------------
'	SAVE MASTER FILE & QUIT
'----------------------------------
wrk.SaveAs save_as_file			'THIS SECTION CAN BE USED TO SET FILE TYPE

'----------------------------------------------------------------------------
'	DIFFERENT FILE TYPES
'------------------------------------------------------------------------------
'wrk.SaveAs ave_as_file, -4158			'Save as TAB DELIMITED File	
'wrk.SaveAs ave_as_file, 6			'Save as a CSV File


wrk.Close
Set wrkSht = Nothing
Set wrk = Nothing

xl.Quit
Set xl = Nothing

Wscript.echo "Done."
__________________
That's 'cause droids don't pull people's arms out of their sockets when they lose. Wookies are known to do that.

Last edited by Shadow Wizard : September 18th, 2006 at 06:43 AM.

Reply With Quote
  #2  
Old July 14th, 2006, 01:02 AM
Nocturns2 Nocturns2 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 60 Nocturns2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 34 m 23 sec
Reputation Power: 3
you can control where your new sheet gets added with the optional parameters.

wrk.sheets.add([Before], [After], [Count], [Type])

if you don't use the before or after parameter the next sheet gets added before the active sheet.

Reply With Quote
  #3  
Old July 14th, 2006, 01:13 AM
teeheiman's Avatar
teeheiman teeheiman is offline
Let the Wookie Win
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Location: United States, Califonia
Posts: 190 teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 20 h 14 m 39 sec
Reputation Power: 17
what is count and type?
Can you give me an example?
Thanks

Last edited by teeheiman : July 14th, 2006 at 01:17 AM.

Reply With Quote
  #4  
Old July 14th, 2006, 03:34 AM
Nocturns2 Nocturns2 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 60 Nocturns2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 34 m 23 sec
Reputation Power: 3
count is the number of worksheets you want to add.

not the same as worksheets.count, (which is the total worksheets in the worksheets collection).

type ... well I'm not too sure about that one. The default type is a regular worksheet. I'm not that familiar with the other types of worksheets that you can specify. Maybe someone else can give you a better explanation about the worksheet types.

all 4 parameters are optional, you don't need to use all of them. for instance, in your code you didn't use any.

Reply With Quote
  #5  
Old July 14th, 2006, 07:15 PM
teeheiman's Avatar
teeheiman teeheiman is offline
Let the Wookie Win
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Location: United States, Califonia
Posts: 190 teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 20 h 14 m 39 sec
Reputation Power: 17
Add Method of Sheets Class Failed

I tried this:
wrk.sheets.add(After)
But Im receving this error on it:
Add Method of Sheets Class Failed

Reply With Quote
  #6  
Old July 17th, 2006, 05:55 PM
teeheiman's Avatar
teeheiman teeheiman is offline
Let the Wookie Win
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Location: United States, Califonia
Posts: 190 teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level)teeheiman User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 20 h 14 m 39 sec
Reputation Power: 17
Heres the correct codeing:

Code:
wrk.sheets.add ,wrk.sheets(wrk.sheets.count)


as for wrk is pointing to the workbook

Reply With Quote
Closed Thread

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Excel Application


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT