Solved

Excel and VB?! y it happen???! (urgent for me) thankz

Posted on 2001-06-27
2
175 Views
Last Modified: 2010-05-02
dearest expert,
actually im already successful in writing my excel spreadsheet by using VB. there was no problem at all

this is the format im using to create it.
=====================================================
Function excelIn(ByVal sExcelFile2 As String)

'sExcelFile2 is "Myexcel.xls"

Dim ExcelFSO As New FileSystemObject
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim copyFile As File

On Error GoTo ErrExcel

'Set xlApp = New Excel.Application

On Error GoTo ErrExcel

Set xlApp = CreateObject("Excel.Application")

On Error GoTo ErrExcel

    Set copyFile = ExcelFSO.GetFile(sExcelFile2)

    Set xlBook = xlApp.Workbooks.Open(sExcelFile2)

    With xlBook.Worksheets("Master TPM").Select

      lnum = 5
       For Each myroe In Cells().CurrentRegion.Rows
        If (xlApp.Cells(lnum, 1)) <> "" Then
            lnum = lnum + 1
            GoTo CountAgain      
        Else
            GoTo NextStage
        End If

       Next

NextStage:

        xlApp.Cells(lnum, 1) = (sSystemDate, "mm/dd/yy"))
        xlApp.Cells(lnum, 2) = sMySite
        xlApp.Cells(lnum, 3) = sMyChannel
        Columns("A:A").EntireColumn.AutoFit
        Columns("B:B").EntireColumn.AutoFit
        Columns("C:C").EntireColumn.AutoFit
    End With

ErrExcel:
    sOUT = "There was an error in excel" & vbCrLf & Error$
    sOUT = "ERR:" & str(Now) & " Emg:" & sOUT
   
exitdoor:
    xlBook.Save
    xlBook.Close
    xlApp.Quit
    Set copyFile = Nothing
    Set xlBook = Nothing
    Set xlApp = Nothing
    Set ExcelFSO = Nothing
===================================================
now im need to do another excel file. let say name is as myExcel2.xls
so in this case i still use the same code as wat im mention above.cz this two xls file is in the same format n same data..the different is jst on their file name.
but when come to that  "for each myroe.cells().." there got an error message call " METHODS 'CELLS' OF OBJECT '_GLOBAL' FAILED"
hw come this will happen when im wanna write data in to myExcel2.xls but there was no error in myexcel.xls.
why it happen???
can u jst help me ???
need it by tomolo...hw..
0
Comment
Question by:babygirls
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
chandukb earned 100 total points
ID: 6231777
You have to add xlapp.

For Each myroe In Cells().CurrentRegion.Rows
       

Replace the above with
For Each myroe in xlapp.Cells().currentregion.rows


Chandu
0
 

Author Comment

by:babygirls
ID: 6233777
Dear Chandukb,
thankz for ur answer...
but i still dun understand y in myexcel.xls i can jst type in For Each myroe In Cells().CurrentRegion.Rows without xlapp.cells()

but for myexcel2.xls
i hv to use that.
wat is the exact problem ?
may i knw about that?
thakz again

babygirls
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month2 days, 19 hours left to enroll

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question