Question

MORE THEN THREE EXCEL WORKSHEET??

Asked by: erichuang

I use the excel worksheet,and got ONE problem.
that is problem is ,If I use more then 3 worksheet.
the complier would tell me.
I couldn't use worksheet(4).
How could I solve this problem?

my source code is
.....
Dim xlApp1 As Excel.Application
....
Set xlApp = New Excel.Application
xlApp.Workbooks.Add
........
do
  if
  xlApp.ActiveWorkbook.Worksheets(1).Name = "0809rsp"
  xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 5) = Mid(strTextLine, 46, 8)
......
  elseif
  xlApp.ActiveWorkbook.Worksheets(2).Name = "0809rsp"
  xlApp.ActiveWorkbook.Worksheets(2).Cells(i, 5) = Mid(strTextLine, 46, 8)
......
  elseif
  xlApp.ActiveWorkbook.Worksheets(3).Name = "0809rsp"
  xlApp.ActiveWorkbook.Worksheets(3).Cells(i, 5) = Mid(strTextLine, 46, 8)
......
  elseif  ' I got problem in here
   xlApp.ActiveWorkbook.Worksheets(4).Name = "0809rsp"
  xlApp.ActiveWorkbook.Worksheets(4).Cells(i, 5) = Mid(strTextLine, 46, 8)
......
  else
 

Loop While Not EOF(1)
 xlApp.ActiveWorkbook.Worksheets(1).SaveAs "c:\Temp.xls"
 xlApp.ActiveWorkbook.Close
 
   
   xlApp.Quit
   
   Set xlApp = Nothing

THANKS FOR YOUR HELP!!!!
          ERIC

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2001-11-25 at 19:17:08ID20240264
Topic

Visual Basic Programming

Participating Experts
2
Points
150
Comments
15

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Dim Excel as Object or as Excel.Application
    I am creating a VB app that opens and Excel spreadsheet and does some manipulation and then pastes the values to a new worksheet and then closes the whole app out. I am using a reference to the Excel 8.0 Library and I cannot seem to find a consistent line of coding to use. If...
  2. Excel.Application
    Hi all. I write an asp page to open an excel file then read/write some cell in that file. Here is my source: Dim xlApp Dim xlBook Dim xlSheet Set xlApp = Server.CreateObject("Excel.Application") 'Set xlBook = xlApp.Workbooks.Add Set ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: thuanncPosted on 2001-11-25 at 19:50:09ID: 6651870

1. You can set number of sheet in new workbook  

xlApp.SheetsInNewWorkbook = 10 'Ten sheet in workbook
Set wkbNew = Workbooks.Add

2. You should navigate valid sheet in sheets collection to access sheets otherwise you may cause error

3. You can add more sheet by following instruction

xlApp.ActiveWorkbook.Worksheets.Add

 

by: erichuangPosted on 2001-11-25 at 21:48:04ID: 6651999

thanks for your reply!
but I don't understand
Set wkbNew = Workbooks.Add ???

I just write a new code.
like
Dim xlApp1 As Excel.Application
....
Set xlApp = New Excel.Application
xlApp.SheetsInNewWorkbook = 4
xlApp.Workbooks.Add
........
do
 if
 xlApp.ActiveWorkbook.Worksheets(1).Name = "0809rsp"
 xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 5) = Mid(strTextLine, 46, 8)
......
 elseif
 xlApp.ActiveWorkbook.Worksheets(2).Name = "0809rsp"
 xlApp.ActiveWorkbook.Worksheets(2).Cells(i, 5) = Mid(strTextLine, 46, 8)
......
 elseif
 xlApp.ActiveWorkbook.Worksheets(3).Name = "0809rsp"
 xlApp.ActiveWorkbook.Worksheets(3).Cells(i, 5) = Mid(strTextLine, 46, 8)
......
 elseif  ' I got problem in here
  xlApp.ActiveWorkbook.Worksheets(4).Name = "0809rsp"
 xlApp.ActiveWorkbook.Worksheets(4).Cells(i, 5) = Mid(strTextLine, 46, 8)
......
 else
 

Loop While Not EOF(1)
xlApp.ActiveWorkbook.Worksheets(1).SaveAs "c:\Temp.xls"
xlApp.ActiveWorkbook.Close
 
 
  xlApp.Quit
 
  Set xlApp = Nothing
But I am not sure is current!!!!so,Could you tell me How to use those method?

sorry to cause your problem.
It is My first to use Visual Basic
before ,I always use the C++.
Thanks ..
best regards
                  erichuang

 

by: erichuangPosted on 2001-11-25 at 22:09:01ID: 6652014

thanks for your reply!
but I don't understand
Set wkbNew = Workbooks.Add ???

I just write a new code.
like
Dim xlApp1 As Excel.Application
....
Set xlApp = New Excel.Application
xlApp.SheetsInNewWorkbook = 4
xlApp.Workbooks.Add
........
do
 if
 xlApp.ActiveWorkbook.Worksheets(1).Name = "0809rsp"
 xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 5) = Mid(strTextLine, 46, 8)
......
 elseif
 xlApp.ActiveWorkbook.Worksheets(2).Name = "0809rsp"
 xlApp.ActiveWorkbook.Worksheets(2).Cells(i, 5) = Mid(strTextLine, 46, 8)
......
 elseif
 xlApp.ActiveWorkbook.Worksheets(3).Name = "0809rsp"
 xlApp.ActiveWorkbook.Worksheets(3).Cells(i, 5) = Mid(strTextLine, 46, 8)
......
 elseif  ' I got problem in here
  xlApp.ActiveWorkbook.Worksheets(4).Name = "0809rsp"
 xlApp.ActiveWorkbook.Worksheets(4).Cells(i, 5) = Mid(strTextLine, 46, 8)
......
 else
 

Loop While Not EOF(1)
xlApp.ActiveWorkbook.Worksheets(1).SaveAs "c:\Temp.xls"
xlApp.ActiveWorkbook.Close
 
 
  xlApp.Quit
 
  Set xlApp = Nothing
But I am not sure is current!!!!so,Could you tell me How to use those method?

sorry to cause your problem.
It is My first to use Visual Basic
before ,I always use the C++.
Thanks ..
best regards
                  erichuang

 

by: thuanncPosted on 2001-11-26 at 00:47:11ID: 6652156

line
Set wkbNew = xlApp.Workbooks.Add
is similar line
xlApp.Workbooks.Add
except that first line will set new worksheet to wbkNew variable. if you dont want to set new to variable thus use the second one

 

by: meekerPosted on 2001-11-26 at 05:01:15ID: 6652498

Alternatively, you can manually add worksheets - excel opens 3 by default, to manually add another, you do...

 xlApp.ActiveWorkbook.Worksheets.Add

 

by: erichuangPosted on 2001-11-26 at 17:22:43ID: 6654103

I just use the
xlApp.SheetsInNewWorkbook = 10 'Ten sheet in workbook
Set wkbNew = Workbooks.Add

With xlApp.ActiveWorkbook.Worksheets(4)
   .Add
   .Cells(y, 1) = Mid(strTextLine, 1, 10)
End With
but the program appears following systex error.
wkbNew not define
and .Add is not the member of worksheets
...
excuse me,Your mean is,The excel workbook provide three worksheets.If I want to use the worksheet(4).
I must create a new workbook.
but I don't understand,If I declare a new workbook,the new one has possible to cover the old one.

another question,Before I run my program,It always show "do you want to save to c:\temp.xls".If I want to saveto c:\temp.xls directly.How would I do?

I paste my full code to reference.
thanks....

'######################################################################################
'#Project Name :Credit Card Transfer to Excel program
'#REQUEST DATA:90/10/30
'#CODING DATA:90/11/2 ~ 90/11/6
'#SA:ERIC HUANG
'#PROGRAMMER:ERIC HUANG
'#######################################################################################
'Dim conn As New ADODB.Connection
'Dim rs As New ADODB.Recordset
'Dim command1 As New ADODB.Command
'Dim intExcel As New Excel.Application
'Dim ExcelWork As New Excel.Workbook
'Dim ExcelSheet As New Excel.Worksheet
'Dim excelRec As New Recordset

'Dim dta As New DataReport

'Private dba As Database

Option Explicit

Private Sub traExcel_Click()
     Dim strTxtName As String        'file name
     Dim strTextLine As String       'text line verible
     Dim i As Integer                '????
     Dim checkStr As String          '?z??????
     Dim j As Integer                '????
     Dim k As Integer                '????
     Dim l As Integer                '????
     Dim m As Integer                '????
     Dim n As Integer                '????
     Dim o As Integer                '????
     Dim p As Integer                '????
     Dim q As Integer                '????
     Dim r As Integer                '????
     Dim s As Integer                '????
     Dim t As Integer                '????
     Dim u As Integer
     Dim v As Integer
     Dim w As Integer
     Dim Rej_check As String
     Dim y As Integer
     'Dim Creditcard_No As String    '?????????a
     Dim xlApp As Excel.Application   '?? Microsoft Excel????????????????
     'Dim xlBook As Excel.Workbook     '??????????????????????????
     'Dim xlSheet As Excel.Worksheet.Add
     'Dim xlsheet2 As Excel.Worksheet
     Dim xlApp1 As Excel.Application  ' ??MIRCOSOFT EXCEL ??????????????
         
     Dim App_Amount As Double
     Dim Rej_Amount As Double
     Dim sum As Double
     Dim sum1 As Double
     Dim approved_str As String
     Dim reject_str As String
     Dim car_mark As Variant
     Dim car_mark1 As Variant
     
     Screen.MousePointer = 11
   
   

   '???????????????o?@????????
   '?? Add ????????????????????????????????
    Set xlApp = New Excel.Application
    'Set xlApp1 = New Excel.Application
   
    xlApp.SheetsInNewWorkbook = 5
    Set wkbNew = xlApp.Workbooks.Add
    'xlApp.Workbooks.Add
    'xlApp1.Workbooks.Add
   
   
    'Set xlBook = xlApp.Workbooks.Add
    'Set xlSheet = xlBook.Worksheets(1).Add
    'Set xlsheet2 = xlBook.Worksheets
   
   
      strTxtName = "c:\nccc\prod\080901\0809rsp.txt"
     
        Open strTxtName For Input As #1
             
             xlApp.ActiveWorkbook.Worksheets(1).Name = "0809rsp"
             
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 1) = "????????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 2) = "?????C????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 3) = "????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 4) = "???????~"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 5) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 6) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 7) = "????????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 8) = "????????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 9) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 10) = "????????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 11) = "????????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 12) = "?????r?g"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 13) = "???????a"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 14) = "??????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 15) = "FILLER"
             '?????????????^
             xlApp.ActiveWorkbook.Worksheets(2).Name = "0809_Approved"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 1) = "????????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 2) = "?????C????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 3) = "????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 4) = "???????~"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 5) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 6) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 7) = "????????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 8) = "????????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 9) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 10) = "????????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 11) = "????????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 12) = "?????r?g"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 13) = "???????a"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 14) = "??????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 15) = "FILLER"
             '?????????????^
             xlApp.ActiveWorkbook.Worksheets(3).Name = "0809_Rejected-????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 1) = "????????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 2) = "?????C????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 3) = "????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 4) = "???????~"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 5) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 6) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 7) = "????????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 8) = "????????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 9) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 10) = "????????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 11) = "????????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 12) = "?????r?g"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 13) = "???????a"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 14) = "??????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 15) = "FILLER"
             '?????????????^
             xlApp.ActiveWorkbook.Worksheets(4).Name = "0809_Rejected-?C??"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 1) = "????????"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 2) = "?????C????"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 3) = "????"
1            xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 4) = "???????~"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 5) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 6) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 7) = "????????"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 8) = "????????"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 9) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 10) = "????????"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 11) = "????????"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 12) = "?????r?g"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 13) = "???????a"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 14) = "??????"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 15) = "FILLER"
            ' Creditcard_No = ""
             App_Amount = 0
             Rej_Amount = 0
             j = 0
             k = 0
             l = 0
             m = 0
             n = 0
             o = 0
             p = 0
             q = 0
             r = 0
             s = 0
             t = 0
             u = 0
             i = 2
             v = 2
             w = 2
             Do
                      Line Input #1, strTextLine
                   
                 
                         With xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 1)
                                  .Value = CStr(Mid(strTextLine, 1, 10))
                                  .NumberFormat = "0"
                         End With
                         'xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 1) = Mid(strTextLine, 1, 10)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 2) = Mid(strTextLine, 11, 8)
                         'Creditcard_No = Mid(strTextLine, 19, 19)
                         With xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 3)
                                  .Value = CStr(Mid(strTextLine, 19, 19))
                                  .NumberFormat = "0"
                         End With
                         'xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 3) = Mid(strTextLine, 19, 19)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 4) = Mid(strTextLine, 38, 8)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 5) = Mid(strTextLine, 46, 8)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 6) = Mid(strTextLine, 54, 2)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 7) = Mid(strTextLine, 56, 6)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 8) = Mid(strTextLine, 62, 4)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 9) = Mid(strTextLine, 66, 3)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 10) = Mid(strTextLine, 69, 16)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 11) = Mid(strTextLine, 85, 6)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 12) = Mid(strTextLine, 91, 6)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 13) = Mid(strTextLine, 97, 6)
                         'car_mark = Mid(strTextLine, 97, 1)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 14) = Mid(strTextLine, 113, 6)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 15) = Mid(strTextLine, 119, 2)
                         checkStr = Trim(Mid(strTextLine, 69, 8))
                         car_mark = Mid(strTextLine, 97, 1)
                         car_mark1 = Mid(strTextLine, 97, 2)
                         Rej_check = Mid(strTextLine, 69, 8)
                         
                         If checkStr = "APPROVED" Then 'APPROVED ????????,????????
                             j = j + 1
                             sum = 0
                             sum = Mid(strTextLine, 38, 8)
                             App_Amount = sum + App_Amount
                             
                             With xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 1)
                                  .Value = CStr(Mid(strTextLine, 1, 10))
                                  .NumberFormat = "0"
                             End With
 
                             'xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 1) = Mid(strTextLine, 1, 10)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 2) = Mid(strTextLine, 11, 8)
                             With xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 3)
                                  .Value = CStr(Mid(strTextLine, 19, 19))
                                  .NumberFormat = "0"
                             End With
                             'xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 3) = Mid(strTextLine, 19, 19)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 4) = Mid(strTextLine, 38, 8)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 5) = Mid(strTextLine, 46, 8)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 6) = Mid(strTextLine, 54, 2)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 7) = Mid(strTextLine, 56, 6)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 8) = Mid(strTextLine, 62, 4)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 9) = Mid(strTextLine, 66, 3)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 10) = Mid(strTextLine, 69, 16)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 11) = Mid(strTextLine, 85, 6)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 12) = Mid(strTextLine, 91, 6)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 13) = Mid(strTextLine, 97, 6)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 14) = Mid(strTextLine, 113, 6)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 15) = Mid(strTextLine, 119, 2)
                             v = v + 1
                         Else
                             If car_mark = ("B") Or car_mark = ("C") Then
                       
                                 
                                   With xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 1)
                                      .Value = CStr(Mid(strTextLine, 1, 10))
                                      .NumberFormat = "0"
                                   End With
 
                                   'xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 1) = Mid(strTextLine, 1, 10)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 2) = Mid(strTextLine, 11, 8)
                                   With xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 3)
                                      .Value = CStr(Mid(strTextLine, 19, 19))
                                      .NumberFormat = "0"
                                   End With
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 3) = Mid(strTextLine, 19, 19)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 4) = Mid(strTextLine, 38, 8)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 5) = Mid(strTextLine, 46, 8)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 6) = Mid(strTextLine, 54, 2)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 7) = Mid(strTextLine, 56, 6)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 8) = Mid(strTextLine, 62, 4)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 9) = Mid(strTextLine, 66, 3)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 10) = Mid(strTextLine, 69, 16)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 11) = Mid(strTextLine, 85, 6)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 12) = Mid(strTextLine, 91, 6)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 13) = Mid(strTextLine, 97, 6)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 14) = Mid(strTextLine, 113, 6)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 15) = Mid(strTextLine, 119, 2)
                                   w = w + 1
                                 
                             ElseIf car_mark = ("S") Or car_mark1 = ("CS") Then
                                   
                                   With xlApp.ActiveWorkbook.Worksheets(4)
                                     .Add
                                     .Cells(y, 1) = Mid(strTextLine, 1, 10)
                                   End With
                                   
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 2) = Mid(strTextLine, 11, 8)
                                   'With xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 3)
                                   '   .Value = CStr(Mid(strTextLine, 19, 19))
                                   '   .NumberFormat = "0"
                                   'End With
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 3) = Mid(strTextLine, 19, 19)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 4) = Mid(strTextLine, 38, 8)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 5) = Mid(strTextLine, 46, 8)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 6) = Mid(strTextLine, 54, 2)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 7) = Mid(strTextLine, 56, 6)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 8) = Mid(strTextLine, 62, 4)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 9) = Mid(strTextLine, 66, 3)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 10) = Mid(strTextLine, 69, 16)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 11) = Mid(strTextLine, 85, 6)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 12) = Mid(strTextLine, 91, 6)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 13) = Mid(strTextLine, 97, 6)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 14) = Mid(strTextLine, 113, 6)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 15) = Mid(strTextLine, 119, 2)
                                   
                                   y = y + 1
                                Else
                               
                             End If
                                 
                                  If checkStr = "REJECT" Then 'Reject ?l???y?????^????????
                                    k = k + 1
                                    sum1 = 0
                                    sum1 = Mid(strTextLine, 38, 8)
                                    Rej_Amount = sum1 + Rej_Amount
                                  ElseIf checkStr = "REJECT C" Then 'Reject Car-Err
                                    l = l + 1
                                  ElseIf checkStr = "VISA LIN" Then 'VISA LINE DOWN VISA ???????????????r???F?e?`
                                    m = m + 1
                                  ElseIf checkStr = "PICK UP" Then 'PICK UP CARD ?l???y?????]??????
                                    n = n + 1
                                  ElseIf checkStr = "HOST DOW" Then 'HOST DOWN NCCC???????????????????r???r????
                                    o = o + 1
                                  ElseIf checkStr = "TIME OU" Then 'NCCC ???????????????????r,?????^????????
                                    p = p + 1
                                  ElseIf checkStr = "TC ERROR" Then 'TRANSCACTION CODE ERROR
                                    q = q + 1
                                  ElseIf checkStr = "SYSTE E" Then 'SYSTEM ERROR?????????e?`
                                    r = r + 1
                                  ElseIf checkStr = "CALL BAN" Then '?l?????????????????M????
                                    s = s + 1
                                  ElseIf checkStr = "EXPIRED" Then 'Expired Card
                                    t = t + 1
                                  Else
                                      'MsgBox ("???????r")
                                  End If
                         
                   
                   'i = i + 1
                   
             End If
             i = i + 1
             Loop While Not EOF(1)
         
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 2, 1) = "Item"
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 2, 2) = "Rrcord"
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 2, 3) = "Amount"
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 3, 1) = "Approved"
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 3, 2) = j
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 3, 3) = App_Amount
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 4, 1) = "Rejected"
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 4, 2) = k
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 4, 3) = Rej_Amount
         xlApp.ActiveWorkbook.Worksheets(2).Cells(v + 2, 1) = "Item"
         xlApp.ActiveWorkbook.Worksheets(2).Cells(v + 2, 2) = "Record"
         xlApp.ActiveWorkbook.Worksheets(2).Cells(v + 2, 3) = "Amount"
         xlApp.ActiveWorkbook.Worksheets(2).Cells(v + 3, 1) = "Approved"
         xlApp.ActiveWorkbook.Worksheets(2).Cells(v + 3, 2) = j
         xlApp.ActiveWorkbook.Worksheets(2).Cells(v + 3, 3) = App_Amount
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 1) = "Item"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 2) = "Record"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 3) = "Amount"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 1) = "Rejected"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 2) = k
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 3) = Rej_Amount
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 5) = "Reject Crd_Err"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 6) = ""
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 5) = "?????????????g"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 6) = l
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 9) = "Expired Card"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 10) = ""
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 9) = "????????-???^????"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 10) = t
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 12) = "U Card(ALPS eXTRACTED Err)"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 13) = ""
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 12) = "Extracted Error"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 13) = 0 'i don't uderstand what's mean of this field.
         
         
         
         
         
         
         
         
         
      '????????????
      xlApp.ActiveWorkbook.SaveAs "c:\temp.xls"
     
     
      'With xlApp.ActiveWorkbook
        '.Worksheets (1)
        '.SaveAs "c:\Temp.xls"
        '.Worksheets (2)
        '.SaveAs "c:\Temp.xls"
        '.Worksheets (3)
        '.SaveAs "c:\Temp.xls"
      'End With
   ' ?P?]??????
   xlApp.ActiveWorkbook.Close
   
   '?? Quit ?????P?] Microsoft Excel??
   
   xlApp.Quit
   
   '?d????????
   Set xlApp = Nothing
   'Set xlBook = Nothing
   'Set xlSheet = Nothing
  Screen.MousePointer = 0
  MsgBox ("?D?n????")
End Sub

Private Sub EXIT_Click()

End

End Sub

Private Sub Form_Load()
  'Dim connstr As String            'database connection string
 
  'connstr = "provider = Microsoft.Jet.OLEDB.3.51;" & "Data Source = d:\ezfly verision1\ezfly.mdb"
  'conn.Open connstr
  'rs.Open "EZFLY", conn, adOpenKeyset, adLockPessimistic
                 
 
 
 
 
End Sub

 

by: erichuangPosted on 2001-11-26 at 17:23:15ID: 6654104

I just use the
xlApp.SheetsInNewWorkbook = 10 'Ten sheet in workbook
Set wkbNew = Workbooks.Add

With xlApp.ActiveWorkbook.Worksheets(4)
   .Add
   .Cells(y, 1) = Mid(strTextLine, 1, 10)
End With
but the program appears following systex error.
wkbNew not define
and .Add is not the member of worksheets
...
excuse me,Your mean is,The excel workbook provide three worksheets.If I want to use the worksheet(4).
I must create a new workbook.
but I don't understand,If I declare a new workbook,the new one has possible to cover the old one.

another question,Before I run my program,It always show "do you want to save to c:\temp.xls".If I want to saveto c:\temp.xls directly.How would I do?

I paste my full code to reference.
thanks....

'######################################################################################
'#Project Name :Credit Card Transfer to Excel program
'#REQUEST DATA:90/10/30
'#CODING DATA:90/11/2 ~ 90/11/6
'#SA:ERIC HUANG
'#PROGRAMMER:ERIC HUANG
'#######################################################################################
'Dim conn As New ADODB.Connection
'Dim rs As New ADODB.Recordset
'Dim command1 As New ADODB.Command
'Dim intExcel As New Excel.Application
'Dim ExcelWork As New Excel.Workbook
'Dim ExcelSheet As New Excel.Worksheet
'Dim excelRec As New Recordset

'Dim dta As New DataReport

'Private dba As Database

Option Explicit

Private Sub traExcel_Click()
     Dim strTxtName As String        'file name
     Dim strTextLine As String       'text line verible
     Dim i As Integer                '????
     Dim checkStr As String          '?z??????
     Dim j As Integer                '????
     Dim k As Integer                '????
     Dim l As Integer                '????
     Dim m As Integer                '????
     Dim n As Integer                '????
     Dim o As Integer                '????
     Dim p As Integer                '????
     Dim q As Integer                '????
     Dim r As Integer                '????
     Dim s As Integer                '????
     Dim t As Integer                '????
     Dim u As Integer
     Dim v As Integer
     Dim w As Integer
     Dim Rej_check As String
     Dim y As Integer
     'Dim Creditcard_No As String    '?????????a
     Dim xlApp As Excel.Application   '?? Microsoft Excel????????????????
     'Dim xlBook As Excel.Workbook     '??????????????????????????
     'Dim xlSheet As Excel.Worksheet.Add
     'Dim xlsheet2 As Excel.Worksheet
     Dim xlApp1 As Excel.Application  ' ??MIRCOSOFT EXCEL ??????????????
         
     Dim App_Amount As Double
     Dim Rej_Amount As Double
     Dim sum As Double
     Dim sum1 As Double
     Dim approved_str As String
     Dim reject_str As String
     Dim car_mark As Variant
     Dim car_mark1 As Variant
     
     Screen.MousePointer = 11
   
   

   '???????????????o?@????????
   '?? Add ????????????????????????????????
    Set xlApp = New Excel.Application
    'Set xlApp1 = New Excel.Application
   
    xlApp.SheetsInNewWorkbook = 5
    Set wkbNew = xlApp.Workbooks.Add
    'xlApp.Workbooks.Add
    'xlApp1.Workbooks.Add
   
   
    'Set xlBook = xlApp.Workbooks.Add
    'Set xlSheet = xlBook.Worksheets(1).Add
    'Set xlsheet2 = xlBook.Worksheets
   
   
      strTxtName = "c:\nccc\prod\080901\0809rsp.txt"
     
        Open strTxtName For Input As #1
             
             xlApp.ActiveWorkbook.Worksheets(1).Name = "0809rsp"
             
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 1) = "????????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 2) = "?????C????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 3) = "????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 4) = "???????~"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 5) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 6) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 7) = "????????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 8) = "????????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 9) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 10) = "????????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 11) = "????????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 12) = "?????r?g"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 13) = "???????a"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 14) = "??????"
             xlApp.ActiveWorkbook.Worksheets(1).Cells(1, 15) = "FILLER"
             '?????????????^
             xlApp.ActiveWorkbook.Worksheets(2).Name = "0809_Approved"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 1) = "????????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 2) = "?????C????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 3) = "????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 4) = "???????~"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 5) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 6) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 7) = "????????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 8) = "????????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 9) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 10) = "????????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 11) = "????????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 12) = "?????r?g"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 13) = "???????a"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 14) = "??????"
             xlApp.ActiveWorkbook.Worksheets(2).Cells(1, 15) = "FILLER"
             '?????????????^
             xlApp.ActiveWorkbook.Worksheets(3).Name = "0809_Rejected-????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 1) = "????????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 2) = "?????C????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 3) = "????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 4) = "???????~"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 5) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 6) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 7) = "????????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 8) = "????????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 9) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 10) = "????????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 11) = "????????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 12) = "?????r?g"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 13) = "???????a"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 14) = "??????"
             xlApp.ActiveWorkbook.Worksheets(3).Cells(1, 15) = "FILLER"
             '?????????????^
             xlApp.ActiveWorkbook.Worksheets(4).Name = "0809_Rejected-?C??"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 1) = "????????"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 2) = "?????C????"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 3) = "????"
1            xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 4) = "???????~"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 5) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 6) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 7) = "????????"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 8) = "????????"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 9) = "?????a"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 10) = "????????"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 11) = "????????"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 12) = "?????r?g"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 13) = "???????a"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 14) = "??????"
             xlApp.ActiveWorkbook.Worksheets(4).Cells(1, 15) = "FILLER"
            ' Creditcard_No = ""
             App_Amount = 0
             Rej_Amount = 0
             j = 0
             k = 0
             l = 0
             m = 0
             n = 0
             o = 0
             p = 0
             q = 0
             r = 0
             s = 0
             t = 0
             u = 0
             i = 2
             v = 2
             w = 2
             Do
                      Line Input #1, strTextLine
                   
                 
                         With xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 1)
                                  .Value = CStr(Mid(strTextLine, 1, 10))
                                  .NumberFormat = "0"
                         End With
                         'xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 1) = Mid(strTextLine, 1, 10)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 2) = Mid(strTextLine, 11, 8)
                         'Creditcard_No = Mid(strTextLine, 19, 19)
                         With xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 3)
                                  .Value = CStr(Mid(strTextLine, 19, 19))
                                  .NumberFormat = "0"
                         End With
                         'xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 3) = Mid(strTextLine, 19, 19)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 4) = Mid(strTextLine, 38, 8)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 5) = Mid(strTextLine, 46, 8)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 6) = Mid(strTextLine, 54, 2)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 7) = Mid(strTextLine, 56, 6)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 8) = Mid(strTextLine, 62, 4)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 9) = Mid(strTextLine, 66, 3)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 10) = Mid(strTextLine, 69, 16)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 11) = Mid(strTextLine, 85, 6)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 12) = Mid(strTextLine, 91, 6)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 13) = Mid(strTextLine, 97, 6)
                         'car_mark = Mid(strTextLine, 97, 1)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 14) = Mid(strTextLine, 113, 6)
                         xlApp.ActiveWorkbook.Worksheets(1).Cells(i, 15) = Mid(strTextLine, 119, 2)
                         checkStr = Trim(Mid(strTextLine, 69, 8))
                         car_mark = Mid(strTextLine, 97, 1)
                         car_mark1 = Mid(strTextLine, 97, 2)
                         Rej_check = Mid(strTextLine, 69, 8)
                         
                         If checkStr = "APPROVED" Then 'APPROVED ????????,????????
                             j = j + 1
                             sum = 0
                             sum = Mid(strTextLine, 38, 8)
                             App_Amount = sum + App_Amount
                             
                             With xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 1)
                                  .Value = CStr(Mid(strTextLine, 1, 10))
                                  .NumberFormat = "0"
                             End With
 
                             'xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 1) = Mid(strTextLine, 1, 10)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 2) = Mid(strTextLine, 11, 8)
                             With xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 3)
                                  .Value = CStr(Mid(strTextLine, 19, 19))
                                  .NumberFormat = "0"
                             End With
                             'xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 3) = Mid(strTextLine, 19, 19)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 4) = Mid(strTextLine, 38, 8)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 5) = Mid(strTextLine, 46, 8)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 6) = Mid(strTextLine, 54, 2)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 7) = Mid(strTextLine, 56, 6)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 8) = Mid(strTextLine, 62, 4)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 9) = Mid(strTextLine, 66, 3)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 10) = Mid(strTextLine, 69, 16)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 11) = Mid(strTextLine, 85, 6)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 12) = Mid(strTextLine, 91, 6)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 13) = Mid(strTextLine, 97, 6)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 14) = Mid(strTextLine, 113, 6)
                             xlApp.ActiveWorkbook.Worksheets(2).Cells(v, 15) = Mid(strTextLine, 119, 2)
                             v = v + 1
                         Else
                             If car_mark = ("B") Or car_mark = ("C") Then
                       
                                 
                                   With xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 1)
                                      .Value = CStr(Mid(strTextLine, 1, 10))
                                      .NumberFormat = "0"
                                   End With
 
                                   'xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 1) = Mid(strTextLine, 1, 10)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 2) = Mid(strTextLine, 11, 8)
                                   With xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 3)
                                      .Value = CStr(Mid(strTextLine, 19, 19))
                                      .NumberFormat = "0"
                                   End With
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 3) = Mid(strTextLine, 19, 19)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 4) = Mid(strTextLine, 38, 8)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 5) = Mid(strTextLine, 46, 8)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 6) = Mid(strTextLine, 54, 2)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 7) = Mid(strTextLine, 56, 6)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 8) = Mid(strTextLine, 62, 4)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 9) = Mid(strTextLine, 66, 3)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 10) = Mid(strTextLine, 69, 16)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 11) = Mid(strTextLine, 85, 6)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 12) = Mid(strTextLine, 91, 6)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 13) = Mid(strTextLine, 97, 6)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 14) = Mid(strTextLine, 113, 6)
                                   xlApp.ActiveWorkbook.Worksheets(3).Cells(w, 15) = Mid(strTextLine, 119, 2)
                                   w = w + 1
                                 
                             ElseIf car_mark = ("S") Or car_mark1 = ("CS") Then
                                   
                                   With xlApp.ActiveWorkbook.Worksheets(4)
                                     .Add
                                     .Cells(y, 1) = Mid(strTextLine, 1, 10)
                                   End With
                                   
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 2) = Mid(strTextLine, 11, 8)
                                   'With xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 3)
                                   '   .Value = CStr(Mid(strTextLine, 19, 19))
                                   '   .NumberFormat = "0"
                                   'End With
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 3) = Mid(strTextLine, 19, 19)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 4) = Mid(strTextLine, 38, 8)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 5) = Mid(strTextLine, 46, 8)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 6) = Mid(strTextLine, 54, 2)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 7) = Mid(strTextLine, 56, 6)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 8) = Mid(strTextLine, 62, 4)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 9) = Mid(strTextLine, 66, 3)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 10) = Mid(strTextLine, 69, 16)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 11) = Mid(strTextLine, 85, 6)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 12) = Mid(strTextLine, 91, 6)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 13) = Mid(strTextLine, 97, 6)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 14) = Mid(strTextLine, 113, 6)
                                   'xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 15) = Mid(strTextLine, 119, 2)
                                   
                                   y = y + 1
                                Else
                               
                             End If
                                 
                                  If checkStr = "REJECT" Then 'Reject ?l???y?????^????????
                                    k = k + 1
                                    sum1 = 0
                                    sum1 = Mid(strTextLine, 38, 8)
                                    Rej_Amount = sum1 + Rej_Amount
                                  ElseIf checkStr = "REJECT C" Then 'Reject Car-Err
                                    l = l + 1
                                  ElseIf checkStr = "VISA LIN" Then 'VISA LINE DOWN VISA ???????????????r???F?e?`
                                    m = m + 1
                                  ElseIf checkStr = "PICK UP" Then 'PICK UP CARD ?l???y?????]??????
                                    n = n + 1
                                  ElseIf checkStr = "HOST DOW" Then 'HOST DOWN NCCC???????????????????r???r????
                                    o = o + 1
                                  ElseIf checkStr = "TIME OU" Then 'NCCC ???????????????????r,?????^????????
                                    p = p + 1
                                  ElseIf checkStr = "TC ERROR" Then 'TRANSCACTION CODE ERROR
                                    q = q + 1
                                  ElseIf checkStr = "SYSTE E" Then 'SYSTEM ERROR?????????e?`
                                    r = r + 1
                                  ElseIf checkStr = "CALL BAN" Then '?l?????????????????M????
                                    s = s + 1
                                  ElseIf checkStr = "EXPIRED" Then 'Expired Card
                                    t = t + 1
                                  Else
                                      'MsgBox ("???????r")
                                  End If
                         
                   
                   'i = i + 1
                   
             End If
             i = i + 1
             Loop While Not EOF(1)
         
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 2, 1) = "Item"
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 2, 2) = "Rrcord"
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 2, 3) = "Amount"
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 3, 1) = "Approved"
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 3, 2) = j
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 3, 3) = App_Amount
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 4, 1) = "Rejected"
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 4, 2) = k
         xlApp.ActiveWorkbook.Worksheets(1).Cells(i + 4, 3) = Rej_Amount
         xlApp.ActiveWorkbook.Worksheets(2).Cells(v + 2, 1) = "Item"
         xlApp.ActiveWorkbook.Worksheets(2).Cells(v + 2, 2) = "Record"
         xlApp.ActiveWorkbook.Worksheets(2).Cells(v + 2, 3) = "Amount"
         xlApp.ActiveWorkbook.Worksheets(2).Cells(v + 3, 1) = "Approved"
         xlApp.ActiveWorkbook.Worksheets(2).Cells(v + 3, 2) = j
         xlApp.ActiveWorkbook.Worksheets(2).Cells(v + 3, 3) = App_Amount
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 1) = "Item"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 2) = "Record"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 3) = "Amount"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 1) = "Rejected"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 2) = k
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 3) = Rej_Amount
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 5) = "Reject Crd_Err"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 6) = ""
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 5) = "?????????????g"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 6) = l
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 9) = "Expired Card"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 10) = ""
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 9) = "????????-???^????"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 10) = t
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 12) = "U Card(ALPS eXTRACTED Err)"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 2, 13) = ""
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 12) = "Extracted Error"
         xlApp.ActiveWorkbook.Worksheets(3).Cells(w + 3, 13) = 0 'i don't uderstand what's mean of this field.
         
         
         
         
         
         
         
         
         
      '????????????
      xlApp.ActiveWorkbook.SaveAs "c:\temp.xls"
     
     
      'With xlApp.ActiveWorkbook
        '.Worksheets (1)
        '.SaveAs "c:\Temp.xls"
        '.Worksheets (2)
        '.SaveAs "c:\Temp.xls"
        '.Worksheets (3)
        '.SaveAs "c:\Temp.xls"
      'End With
   ' ?P?]??????
   xlApp.ActiveWorkbook.Close
   
   '?? Quit ?????P?] Microsoft Excel??
   
   xlApp.Quit
   
   '?d????????
   Set xlApp = Nothing
   'Set xlBook = Nothing
   'Set xlSheet = Nothing
  Screen.MousePointer = 0
  MsgBox ("?D?n????")
End Sub

Private Sub EXIT_Click()

End

End Sub

Private Sub Form_Load()
  'Dim connstr As String            'database connection string
 
  'connstr = "provider = Microsoft.Jet.OLEDB.3.51;" & "Data Source = d:\ezfly verision1\ezfly.mdb"
  'conn.Open connstr
  'rs.Open "EZFLY", conn, adOpenKeyset, adLockPessimistic
                 
 
 
 
 
End Sub

 

by: erichuangPosted on 2001-11-26 at 20:06:58ID: 6654302

???? is the chinese Word.

 

by: erichuangPosted on 2001-11-26 at 20:07:03ID: 6654303

???? is the chinese Word.

 

by: thuanncPosted on 2001-11-26 at 23:05:22ID: 6654520

1. You can create new workbook with more than 3 worksheet as following:

xlApp.SheetsInNewWorkbook = 10 'Ten sheet in workbook
xlApp.Workbooks.Add

2. if you have old workbook with less than number of worksheet as you need you can add more worksheet:

xlApp.Worksheets.Add , xlApp.ActiveWorksheet

3. You can save your document without confirm (to c:\)
'delete old file
If Dir("c:\filename.xls") <> "" Then Kill "c:\filename.xls"
xlApp.ActiveWorkbook.SaveAs "c:\filename.xls"
xlApp.Quit
Set xlApp= Nothing

4. Here is may example for you. This will add more worksheet (or sheet) if needed and then add data to sheet
    Dim Rpt As Excel.Application
    Set Rpt = New Excel.Application
    If Rpt.Workbooks.Count = 0 Then
        Rpt.Workbooks.Add
        Rpt.Sheets(1).Activate
    Else
        If Rpt.ActiveSheet.Index = Rpt.Sheets.Count Then
            Rpt.Sheets.Add , Rpt.ActiveSheet
        Else
            Rpt.Sheets(Rpt.ActiveSheet.Index + 1).Activate
        End If
    End If
  'Set data into cells
    With Rpt.ActiveSheet
        .Cells(3, 2).Value = "xxx"
        .Cells(7, 2).Value = "xxx"
        .Cells(8, 2).Value = "xxx"
        .Cells(9, 2).Value = "xxx"
    End With
 If Dir("c:\rptPXS.xls") <> "" Then Kill "c:\rptPXS.xls"
    Rpt.ActiveWorkbook.SaveAs "c:\rptPXS.xls"
    Rpt.Quit
    Set Rpt = Nothing

 

by: erichuangPosted on 2001-11-27 at 17:31:29ID: 6656932

Dear thuannc:
   thanks for your reply.
   I just test writed by your way last night.
   But I find some error,If I use this way
   ....................
   xlApp.SheetsInNewWorkbook = 4
   xlApp.Workbooks.Add
  .......................
  xlApp.ActiveWorkbook.Worksheets(4).Name = "0809"
  xlApp.ActiveWorkbook.Worksheets(4).cells(1,1) = "0809"
 'will show the current value.
  but when I use the
 Else :
                                   xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 1) = Mid(strTextLine, 1, 10)
xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 1) = Mid(strTextLine, 1, 10)
xlApp.ActiveWorkbook.Worksheets(4).Cells(y, 2) = Mid(strTextLine, 11, 8)
y = y + 1
     
It will show the runtime error "1004"
I don't know what's going on??
Do you give me a hand??
thanks very much??

 

by: thuanncPosted on 2001-11-27 at 17:48:43ID: 6656967

it is normal code but what about y value? let me know value of y variable when error is raised. it is also may be Mid function return null values. You should debug to that line and check return values of Mid function

 

by: erichuangPosted on 2001-11-27 at 20:03:22ID: 6657210

Thanks ,I just find this error.
I should declare Y=2.
The last question,Could you mind tell me,If I want to add the doule line around the cell.
how could I do?
 With xlApp.ActiveWorkbook.Worksheets(1)
         .Cells(i + 2, 1).Font.Bold = True
         .Cells(i + 2, 1) = "Item"
         .Cells(i + 2, 2) = "Rrcord"
         .Cells(i + 2, 3) = "Amount"
         .Cells(i + 3, 1) = "Approved"
         .Cells(i + 3, 2) = j ' value
         .Cells(i + 3, 3) = App_Amount
         End With

'If i wnat to add line around six cells
         
thanks very much your help!!!

 

by: thuanncPosted on 2001-11-28 at 00:15:53ID: 6657556

With xlApp.ActiveWorkbook.Worksheets(1)
    xlApp.Range(.Cells(i + 2, 1), .Cells(i + 3, 3)).Select
 End With
    xlApp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    xlApp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With xlApp.Selection.Borders(xlEdgeLeft)
        .LineStyle = xlDouble
        .Weight = xlThick
        .ColorIndex = xlAutomatic
    End With
    With xlApp.Selection.Borders(xlEdgeTop)
        .LineStyle = xlDouble
        .Weight = xlThick
        .ColorIndex = xlAutomatic
    End With
    With xlApp.Selection.Borders(xlEdgeBottom)
        .LineStyle = xlDouble
        .Weight = xlThick
        .ColorIndex = xlAutomatic
    End With
    With xlApp.Selection.Borders(xlEdgeRight)
        .LineStyle = xlDouble
        .Weight = xlThick
        .ColorIndex = xlAutomatic
    End With
    xlApp.Selection.Borders(xlInsideVertical).LineStyle = xlNone
    xlApp.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

You can find out xlDouble,xlThick... constant from VB (press F2 and search in it) if you include excel class

 

by: erichuangPosted on 2001-11-28 at 00:51:52ID: 6657596

Thanks very much to solve my problem.
I seriouly holp you could help me once again,If I meet trouble next time.
         best regards & having a nice day
                    eric huang

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...