?
Solved

Progress bar question

Posted on 2006-11-10
4
Medium Priority
?
215 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:Yury Merezhkov
[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:Yury Merezhkov
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 2000 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:Yury Merezhkov
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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

752 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