Excel SaveAs()挂起

时间:2018-12-11 08:16:57

标签: excel vb6

我已使用Visual Basic 6将数据导出到excel文件,问题是当我在调试模式下导出时,一切正常,但是当我使exe挂起并且光标不断旋转时,

我在下面给出了导出代码。该程序似乎在SaveAs行处冻结:

On Error GoTo X
Dim iRow As Integer
Dim iCol As Integer
Dim objExcl As Excel.Application
Dim objWk As Excel.Workbook
Dim objSht As Excel.Worksheet
Dim iHead As Integer
Dim vHead As Variant
Dim path As String
Dim VFileNm As String
Dim i As Integer
Dim CmpGstin As String
Set objExcl = New Excel.Application
RptType = 0
Frame6.Visible = True
MDIForm1.Enabled = False
Label3.Caption = "Please wait... Data is Uploading to Excel file"
VFileNm = App.path & "\GSTR2_Excel.xlsx"
Set objWk = objExcl.Workbooks.Open(VFileNm) '"F:\GST_REPORTS\GST_AGENCIES_TAX_NM20\GSTR1_Excel.xlsx")
For i = 1 To 8
    If i = 1 Then
        If TotRcpt > 0 Then
            ChkG2B2b.Value = 1
            Set objSht = objWk.Sheets(2)
        End If
        Next iCol
       Next iRow
   End If
   TotRcpt = 0
Next
cd1.CancelError = True
cd1.FileName = "\GSTR2_" & CmpGstin & "_" & Format(FrmGstRptShow.DTpFrmDt, "MMMMYYYY") & ".xlsx"
cd1.InitDir = ("C:\My Documents")
cd1.Filter = "*.xlsx|*.xlsx"
cd1.FilterIndex = 4
cd1.ShowSave
VFileNm = cd1.FileName
Label3.Caption = "Please Wait... Excel File is Saving"
objWk.SaveAs VFileNm
MsgBox "Export Succecefully "
objWk.Close False
MDIForm1.Enabled = True
Label3.Caption = ""
Set objSht = Nothing
Set objWk = Nothing
Set objExcl = Nothing
Unload Me
X:
'MsgBox Err.Description
MDIForm1.Enabled = True
Label3.Caption = ""
Set objSht = Nothing
Set objWk = Nothing
Set objExcl = Nothing
'objWk.Close False
Unload Me

如果问题是在调试模式下发生的,我本可以设法解决该问题,但是使用EXE运行该问题时会发生。

0 个答案:

没有答案