troubleshooting Question

VB6 - DoEvents problem while extracting to Excel

Avatar of Wilder1626
Wilder1626Flag for Canada asked on
Microsoft OfficeVisual Basic ClassicMicrosoft Excel* vb6
37 Comments1 Solution206 ViewsLast Modified:
Hi

I have this below code that generates BarCodes based on values from my MSHFlexgrid1 while the picture is in a PictureBox ("Picture1")

 when run in the IDE, I have each Picture related to the Value from my MSHFlexgrid1.
Ex:
No issue
When i run it with the .exe, this is when i have the problem where the pictures don't match.
Ex:
with issue
The code i have is:
  xlObj.ActiveWorkbook.ActiveSheet.range("A1") = "BARCODE"
    xlObj.ActiveWorkbook.ActiveSheet.range("B1") = "BARCODE VALUE"
    xlObj.ActiveWorkbook.ActiveSheet.Columns("A").ColumnWidth = 37.59


     With MSHFlexGrid1
        Dim gridRow As Long, xlRow As Long, LastRow As Long, xlDown As Long

        For gridRow = 1 To MSHFlexGrid1.Rows - 1
            If MSHFlexGrid1.TextMatrix(gridRow, 1) <> "" Then
  
                For xlRow = 2 To (MSHFlexGrid1.Rows - 1) + 1
                    If xlObj.ActiveWorkbook.ActiveSheet.Cells(xlRow, 2) = "" Then

                        Form1.Text1.Text = MSHFlexGrid1.TextMatrix(gridRow, 1)
                        makeBC
                        
                        DoEvents

                        '********************************************************************************************************
                        SavePicture Picture1.Image, "C:\Pic.bmp"
                        '********************************************************************************************************

                       ' Sleep 200 ' to sleep for 1 second

                        xlObj.ActiveWorkbook.ActiveSheet.Cells(xlRow, 1).AddComment.Shape.Fill.UserPicture "C:\Pic.bmp"
                        xlObj.ActiveWorkbook.ActiveSheet.Cells(xlRow, 1).Comment.Text " "
                        xlObj.ActiveWorkbook.ActiveSheet.Cells(xlRow, 1).Comment.Height = 660
                        xlObj.ActiveWorkbook.ActiveSheet.Cells(xlRow, 1).Comment.Shape.Width = 200
                        xlObj.ActiveWorkbook.ActiveSheet.Rows(xlRow).RowHeight = 61
                        xlObj.ActiveWorkbook.ActiveSheet.Cells(xlRow, 1).Comment.Visible = True
                        xlObj.ActiveWorkbook.ActiveSheet.Cells(xlRow, 1).Comment.Shape.Top = xlObj.ActiveWorkbook.ActiveSheet.Cells(xlRow, 1).Top
                        xlObj.ActiveWorkbook.ActiveSheet.Cells(xlRow, 1).Comment.Shape.Left = xlObj.ActiveWorkbook.ActiveSheet.Cells(xlRow, 1).Left
                        xlObj.ActiveWorkbook.ActiveSheet.Cells(xlRow, 1).Comment.Shape.Placement = 1

                        xlObj.ActiveWorkbook.ActiveSheet.Cells(xlRow, 2) = Text1.Text
                        xlRow = xlRow + 1

                    End If
                Next xlRow
            End If
        Next gridRow
    End With

I did try "DoEvents' at multiple places but still having the same problem.

How can i fix this?

Thank you for your help.
Extract-to-Excel-issue-no1.zip
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 37 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 37 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros