gingank 0 Junior Poster

Can you all help me slove this problem i using vb to get data from sql then display on Excel but while i click again the same button to display it to Excel it show run time error 91 and debug problem it AppExcel.ActiveWorkbook.Save

Below is the code please help me find the problem thank you.

FileName = "BadgeReturn.xls"
Dim row As Integer
row = 4

If rs.RecordCount > 0 Then
If OpenExcel(FileName) Then
Set wSheet = AppExcel.Sheets(1)
AppExcel.Sheets(1).Name = "BadgeReturn"
With wSheet
ProgressBar.Visible = True
ProgressBar.Max = rs.RecordCount
ProgressBar.Value = 0

Do Until rs.EOF
.Cells(row, 1) = rs!Staff_no
.Cells(row, 2) = rs!staff_Name
.Cells(row, 3) = rs!CostBlock
.Cells(row, 4) = rs!staff_joblevel
.Cells(row, 5) = rs!sec_shortname
.Cells(row, 6) = rs!staff_group
.Cells(row, 7) = rs!returned_id
.Cells(row, 8) = rs!date_insert
rs.MoveNext
row = row + 1

ProgressBar.Value = ProgressBar.Value + 1
Loop

End With


End If


Else
MsgBox "No record have found"
Exit Sub

End If

AppExcel.ActiveWorkbook.Save
AppExcel.Visible = True
Close EndExcel


End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.