Kmahraz
Member
Hello,
I have a userform that I created that has command button to generate a report, for some reason I get the error Run-time error -2147018887 (80071779) with Document not save.
Any idea what can be leading to this issue?
Thank you,
K
I have a userform that I created that has command button to generate a report, for some reason I get the error Run-time error -2147018887 (80071779) with Document not save.
Any idea what can be leading to this issue?
Code:
Private Sub cmdGen_Click()
Dim rng As Range, fnd As Range
Dim WS As Worksheet
Dim fPath As String
Dim fName As String
Dim nWb As Workbook
Set rng = Sheet1.Range("A3:N" & Sheet1.Cells(Rows.Count, "A").End(xlUp).Row)
Set WS = Sheet8
For i% = 0 To frmDataInput.ListBox1.ListCount - 1
If frmDataInput.ListBox1.Selected(i) Then
Set fnd = rng.Find(What:=frmDataInput.ListBox1.List(i), LookAt:=xlWhole)
Sheet8.Name = frmDataInput.ListBox1.List(i)
Sheet8.[B6] = Sheet1.Cells(fnd.Row, 2)
Sheet8.[B7] = Sheet1.Cells(fnd.Row, 3)
Sheet8.[B8] = Sheet1.Cells(fnd.Row, 9)
Sheet8.[B10] = Sheet1.Cells(fnd.Row, 7)
Sheet8.[I6] = Sheet1.Cells(fnd.Row, 11)
Sheet8.[J4] = Sheet1.Cells(fnd.Row, 13)
Set rng = Sheet5.Range("A4:Y" & Sheet5.Cells(Rows.Count, "A").End(xlUp).Row)
Set fnd = rng.Find(What:=frmDataInput.ListBox1.List(i), LookAt:=xlWhole)
Sheet8.[B15] = Sheet5.Cells(fnd.Row, 2)
Sheet8.[B14] = Sheet5.Cells(fnd.Row, 3)
Sheet8.[B16] = Sheet5.Cells(fnd.Row, 4)
Sheet8.[B17] = Sheet5.Cells(fnd.Row, 5)
Sheet8.[G15] = Sheet5.Cells(fnd.Row, 10)
Sheet8.[G14] = Sheet5.Cells(fnd.Row, 11)
Sheet8.[G16] = Sheet5.Cells(fnd.Row, 12)
Sheet8.[G17] = Sheet5.Cells(fnd.Row, 13)
Sheet8.[J15] = Sheet5.Cells(fnd.Row, 18)
Sheet8.[J14] = Sheet5.Cells(fnd.Row, 19)
Sheet8.[J16] = Sheet5.Cells(fnd.Row, 20)
Sheet8.[J17] = Sheet5.Cells(fnd.Row, 21)
fPath = ThisWorkbook.Path & "\"
fName = WS.Name & ".pdf"
WS.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fPath & fName, includedocproperties:=False, openafterpublish:=True
Set nWb = Workbooks.Add
WS.Cells.Copy Destination:=nWb.Sheets("Sheet1").Cells
With ActiveWorkbook
.SaveAs Filename:=fPath & WS.Name & ".xlsx"
.Close (False)
End With
End If
Next
End Sub
K