Results 1 to 5 of 5

Thread: Reading and writing to excel file using ExcelWS.cells(I,j)

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2020
    Posts
    1

    Exclamation Reading and writing to excel file using ExcelWS.cells(I,j)


    I am not It professional
    I learnt VB6 by trial and error and NET
    I am trying to export some textboxes (60).text
    To excel file sheet(2)
    But it was taking long time to export data
    I am using wxcelWS.cells(a,b)=text1(i).text
    Please help me to get process faster.....

  2. #2
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Reading and writing to excel file using ExcelWS.cells(I,j)

    You could do either of the following -
    !) Study up on this(these) - http://www.vbforums.com/showthread.p...6-(or-VB5-VBA)
    2) Attach your project and let some of us have a go
    3) If your project is worth a fortune, and you don't want to attach it, you could PM (Private Message) me (I'm way to old to try to make a fortune from your program)

    Rob

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Reading and writing to excel file using ExcelWS.cells(I,j)

    To excel file sheet(2)
    But it was taking long time to export data
    I am using wxcelWS.cells(a,b)=text1(i).text
    Please help me to get process faster.....
    the actual code might help more
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Reading and writing to excel file using ExcelWS.cells(I,j)

    Shot in the (very) dark: it's a "prepared" Excel-Sheet, with formulas recalculating a bizzillion cells to the data the cells are receiving from his VB6-App-Textboxes
    Nevermind, that we don't see, if it's early or late bound Excel
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Reading and writing to excel file using ExcelWS.cells(I,j)

    Ok, here's my tip on this. While your code is filling the Excel cells, turn off .Calculation and .ScreenUpdating. Then when you're done, turn both of those back on, and then recalculate things.

    Here's a function to turn it off (assuming xls is my Excel object variable):

    Code:
    
    Private Sub TurnOffExcelCalculations(xls As Object)
        xls.Calculation = xlCalculationManual ' Be sure to turn back on.
        xls.ScreenUpdating = False ' Be sure to turn back on.
    End Sub
    
    
    And here's a function to turn it back on:

    Code:
    
    Private Sub TurnOnExcelCalculationsAndRecalculateAll(xls As Object, wbk As Object)
        ' Do NOT use xls.CalculateFullRebuild or xls.CalculateFull or it may find some old formulas and replace things.
        '
        Dim wsh     As Object
        '
        xls.Calculation = xlCalculationAutomatic
        For Each wsh In wbk.Worksheets
            wsh.Calculate
        Next
        xls.ScreenUpdating = True
    End Sub
    
    
    I do a great deal of calculating and reporting with Excel from VB6, and I use these functions often. They'll improve your speed immensely.

    Beyond this, if you're moving large blocks of data into Excel, you might learn how to use 2D arrays to move the data. Moving arrays into Excel is MUCH faster than doing it one-cell-at-a-time. If you need that, I can post something about that as well.

    Best Regards,
    Elroy

    EDIT: Also, I noticed that I'm passing wbk into the TurnOnExcelCalculationsAndRecalculateAll function. This is simply the workbook object (i.e., the actual Excel file) that I'm working on. Typically, I'm just working on one Excel file at any one time, but I'm often working on several worksheets within that file. And this TurnOnExcelCalculationsAndRecalculateAll function accommodates precisely that. If you're only working with one worksheet, just pass in the workbook (wbk) object variable and it'll work fine.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width