Solved

Progress bar question

Posted on 2006-11-10
4
181 Views
Last Modified: 2010-04-30
Hi,

I have this code:

        FileCopy SystemDir & "\Template.xls", cdlg.filename
       
        Set xlApp = CreateObject("Excel.Application")
        Set mysheet = xlApp.Workbooks.Open(cdlg.filename).Sheets(1)
           
        mysheet.Cells(4, 1).Value = Trim(Me.StoreName.Text)
        mysheet.Cells(4, 2).Value = Trim(Me.StoreNumber.Text)
        mysheet.Cells(4, 3).Value = Trim(Me.StoreHours.Text)
        mysheet.Cells(4, 4).Value = Trim(Me.SetPoint.Text)
        mysheet.Cells(4, 5).Value = Trim(Me.Days.Text)
        mysheet.Cells(4, 6).Value = Trim(Me.Employee.Text)
        mysheet.Cells(4, 7).Value = Trim(Me.preOpen.Text)
        mysheet.Cells(4, 8).Value = Trim(Me.Open.Text)
        mysheet.Cells(4, 9).Value = Trim(Me.preClose.Text)
        mysheet.Cells(4, 10).Value = Trim(Me.Unoccupied.Text)
        mysheet.Cells(4, 11).Value = Trim(Me.StoreContact.Text)
        mysheet.Cells(4, 12).Value = Trim(Me.Address.Text)
       
        j = 0
       
        For i = 1 To 12
            If (IsNull(Trim(Me.Controls("DateStart" & i).Text)) Or Trim(Me.Controls("DateStart" & i).Text) = "" Or Trim(Me.Controls("DateStart" & i).Text) = "__/__/____") And _
               (IsNull(Trim(Me.Controls("DateEnd" & i).Text)) Or Trim(Me.Controls("DateEnd" & i).Text) = "" Or Trim(Me.Controls("DateEnd" & i).Text) = "__/__/____") And _
               (IsNull(Trim(Me.Controls("StoreOpen" & i).Text)) Or Trim(Me.Controls("StoreOpen" & i).Text) = "" Or Trim(Me.Controls("StoreOpen" & i).Text) = "__:__ __") And _
               (IsNull(Trim(Me.Controls("StoreClosed" & i).Text)) Or Trim(Me.Controls("StoreClosed" & i).Text) = "" Or Trim(Me.Controls("StoreClosed" & i).Text) = "__:__ __") Then
                j = j + 1
            Else
                mysheet.Cells(i + 3 - j, 13).Value = Trim(Me.Controls("DateStart" & i).Text)
                mysheet.Cells(i + 3 - j, 14).Value = Trim(Me.Controls("DateEnd" & i).Text)
                mysheet.Cells(i + 3 - j, 15).Value = Trim(Me.Controls("StoreOpen" & i).Text)
                mysheet.Cells(i + 3 - j, 16).Value = Trim(Me.Controls("StoreClosed" & i).Text)
            End If
        Next i
       
        mysheet.Application.Windows(Dir$(cdlg.filename)).Visible = True
        mysheet.Application.ActiveWorkbook.Save
        mysheet.Application.ActiveWorkbook.Close
        xlApp.Quit
       
        Set mysheet = Nothing
        MsgBox "Excel file was successfully created!", vbOKOnly, "Done!"
        Me.Command33.Enabled = True
        Me.Command34.Enabled = True


How can I show progress bar while this code is working? I'm using  Microsoft Common Controls Progress Bar. Thanks.
0
Comment
Question by:RealSnaD
  • 2
  • 2
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
you put the progress bar on the form, say barProgress, and have it invisible


        barProgress.Min = 0
        barProgress.Value = 0
        barProgress.Max = 12
        barProgress.visible = true
        FileCopy SystemDir & "\Template.xls", cdlg.filename
       
        Set xlApp = CreateObject("Excel.Application")
        Set mysheet = xlApp.Workbooks.Open(cdlg.filename).Sheets(1)
           
        mysheet.Cells(4, 1).Value = Trim(Me.StoreName.Text)
        mysheet.Cells(4, 2).Value = Trim(Me.StoreNumber.Text)
        mysheet.Cells(4, 3).Value = Trim(Me.StoreHours.Text)
        mysheet.Cells(4, 4).Value = Trim(Me.SetPoint.Text)
        mysheet.Cells(4, 5).Value = Trim(Me.Days.Text)
        mysheet.Cells(4, 6).Value = Trim(Me.Employee.Text)
        mysheet.Cells(4, 7).Value = Trim(Me.preOpen.Text)
        mysheet.Cells(4, 8).Value = Trim(Me.Open.Text)
        mysheet.Cells(4, 9).Value = Trim(Me.preClose.Text)
        mysheet.Cells(4, 10).Value = Trim(Me.Unoccupied.Text)
        mysheet.Cells(4, 11).Value = Trim(Me.StoreContact.Text)
        mysheet.Cells(4, 12).Value = Trim(Me.Address.Text)
       
        j = 0
       
        For i = 1 To 12
           barProgress.Value = i
           doevents
            If (IsNull(Trim(Me.Controls("DateStart" & i).Text)) Or Trim(Me.Controls("DateStart" & i).Text) = "" Or Trim(Me.Controls("DateStart" & i).Text) = "__/__/____") And _
               (IsNull(Trim(Me.Controls("DateEnd" & i).Text)) Or Trim(Me.Controls("DateEnd" & i).Text) = "" Or Trim(Me.Controls("DateEnd" & i).Text) = "__/__/____") And _
               (IsNull(Trim(Me.Controls("StoreOpen" & i).Text)) Or Trim(Me.Controls("StoreOpen" & i).Text) = "" Or Trim(Me.Controls("StoreOpen" & i).Text) = "__:__ __") And _
               (IsNull(Trim(Me.Controls("StoreClosed" & i).Text)) Or Trim(Me.Controls("StoreClosed" & i).Text) = "" Or Trim(Me.Controls("StoreClosed" & i).Text) = "__:__ __") Then
                j = j + 1
            Else
                mysheet.Cells(i + 3 - j, 13).Value = Trim(Me.Controls("DateStart" & i).Text)
                mysheet.Cells(i + 3 - j, 14).Value = Trim(Me.Controls("DateEnd" & i).Text)
                mysheet.Cells(i + 3 - j, 15).Value = Trim(Me.Controls("StoreOpen" & i).Text)
                mysheet.Cells(i + 3 - j, 16).Value = Trim(Me.Controls("StoreClosed" & i).Text)
            End If
        Next i
       
        mysheet.Application.Windows(Dir$(cdlg.filename)).Visible = True
        mysheet.Application.ActiveWorkbook.Save
        mysheet.Application.ActiveWorkbook.Close
        xlApp.Quit
       
        Set mysheet = Nothing
        MsgBox "Excel file was successfully created!", vbOKOnly, "Done!"
        Me.Command33.Enabled = True
        Me.Command34.Enabled = True
       barProgress.visible = false
0
 
LVL 7

Author Comment

by:RealSnaD
Comment Utility
Progressbar becomes visible but nothing is happening in it. Then it just disappears.
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
did you put the line doevents?
note that working on only 12 cells should not really need a progress bar that will be done very fast anyhow.


        barProgress.Min = 0
        barProgress.Value = 0
        barProgress.Max = 7
        barProgress.visible = true
        FileCopy SystemDir & "\Template.xls", cdlg.filename
       
        Set xlApp = CreateObject("Excel.Application")
        barProgress.Value = 1
        doevents
        Set mysheet = xlApp.Workbooks.Open(cdlg.filename).Sheets(1)
           
        barProgress.Value = 2
        doevents
        mysheet.Cells(4, 1).Value = Trim(Me.StoreName.Text)
        mysheet.Cells(4, 2).Value = Trim(Me.StoreNumber.Text)
        mysheet.Cells(4, 3).Value = Trim(Me.StoreHours.Text)
        mysheet.Cells(4, 4).Value = Trim(Me.SetPoint.Text)
        mysheet.Cells(4, 5).Value = Trim(Me.Days.Text)
        mysheet.Cells(4, 6).Value = Trim(Me.Employee.Text)
        mysheet.Cells(4, 7).Value = Trim(Me.preOpen.Text)
        mysheet.Cells(4, 8).Value = Trim(Me.Open.Text)
        mysheet.Cells(4, 9).Value = Trim(Me.preClose.Text)
        mysheet.Cells(4, 10).Value = Trim(Me.Unoccupied.Text)
        mysheet.Cells(4, 11).Value = Trim(Me.StoreContact.Text)
        mysheet.Cells(4, 12).Value = Trim(Me.Address.Text)

        barProgress.Value = 4
        doevents
       
        j = 0
       
        For i = 1 To 12
            If (IsNull(Trim(Me.Controls("DateStart" & i).Text)) Or Trim(Me.Controls("DateStart" & i).Text) = "" Or Trim(Me.Controls("DateStart" & i).Text) = "__/__/____") And _
               (IsNull(Trim(Me.Controls("DateEnd" & i).Text)) Or Trim(Me.Controls("DateEnd" & i).Text) = "" Or Trim(Me.Controls("DateEnd" & i).Text) = "__/__/____") And _
               (IsNull(Trim(Me.Controls("StoreOpen" & i).Text)) Or Trim(Me.Controls("StoreOpen" & i).Text) = "" Or Trim(Me.Controls("StoreOpen" & i).Text) = "__:__ __") And _
               (IsNull(Trim(Me.Controls("StoreClosed" & i).Text)) Or Trim(Me.Controls("StoreClosed" & i).Text) = "" Or Trim(Me.Controls("StoreClosed" & i).Text) = "__:__ __") Then
                j = j + 1
            Else
                mysheet.Cells(i + 3 - j, 13).Value = Trim(Me.Controls("DateStart" & i).Text)
                mysheet.Cells(i + 3 - j, 14).Value = Trim(Me.Controls("DateEnd" & i).Text)
                mysheet.Cells(i + 3 - j, 15).Value = Trim(Me.Controls("StoreOpen" & i).Text)
                mysheet.Cells(i + 3 - j, 16).Value = Trim(Me.Controls("StoreClosed" & i).Text)
            End If
        Next i
       
        barProgress.Value = 5
        doevents
        mysheet.Application.Windows(Dir$(cdlg.filename)).Visible = True
        mysheet.Application.ActiveWorkbook.Save
        mysheet.Application.ActiveWorkbook.Close
        barProgress.Value = 6
        doevents
        xlApp.Quit
       
        barProgress.Value = 7
        doevents
        Set mysheet = Nothing
        MsgBox "Excel file was successfully created!", vbOKOnly, "Done!"
        Me.Command33.Enabled = True
        Me.Command34.Enabled = True
       barProgress.visible = false
0
 
LVL 7

Author Comment

by:RealSnaD
Comment Utility
Perfect! Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now