Solved

Progress bar question

Posted on 2006-11-10
4
206 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
[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
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17916455
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
ID: 17916628
Progressbar becomes visible but nothing is happening in it. Then it just disappears.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 17916722
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
ID: 17917225
Perfect! Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

732 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