Home > Software engineering >  VB6 run normal for the first time, run the second error?
VB6 run normal for the first time, run the second error?

Time:11-17

Form code as shown in figure 2, began to run, form 1, click on the form button 1 uninstall uninstall form 1, form 2, input related information, click the button form 2 1 generation of excel workbook, normal save, then click the button form 2 2, normal unloading form 2, form 1, a cycle is completed, when again click the button 1 form 1, form 1 unloading, form 2, input data, click the button form 2 1, will go wrong, prompt error 91, real-time object variable block or with variable is not set, all out to run is not an error (I put a dot inside. XLS template excel workbook), in addition, how code is the last to the end of measurement of the excel. Exe process? My code, the trouble to help changed, thank you very much,
Private Sub Command1_Click ()
Dim xlApp As New Excel. Application 'definition and create Excel object
Dim xlBook As Excel. The Workbook 'create Workbook
'xlapp. DisplayAlerts=False
XlApp. Visible=True 'to Excel Visible
The Set xlBook=xlApp. Workbooks. Open (App) Path & amp; "/dot. XLS") 'open the Excel template
With xlBook. ActiveSheet
Range (" b4 ")=Text1. Text 'fill the value of the first line of the first column
Range (" i2)=Text2. Text 'fill other ranks the value of the concrete filled position according to the template to do
End With
ActiveSheet. Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, the Password:=1234 'table Set close Set excel_Book=excel_App. Workbooks. Open (App) Path & amp; "\ dot. XLS")
ChDir evaluation table cattle technology "D: "
Dim As Long a
ActiveWorkbook. SaveAs FileName:="evaluation table cattle technology D: \ " & amp; Text1. Text & amp; Text2. Text & amp; ". XLSX ", FileFormat:=_
XlOpenXMLWorkbook CreateBackup:=False
Excel. ActiveWorkbook. Close
The Set excel_App=Nothing
End Sub

CodePudding user response:

First, add a breakpoint newspaper which is in the wrong line,

Second, in the Set excel_App=Nothing advice before closing excel_App object, namely excel_App. Close

CodePudding user response:

ActiveSheet. Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, the Password:=1234 'table Set close Set excel_Book=excel_App. Workbooks. Open (App) Path & amp; "\ dot. XLS")
This line began to report errors,
This code run there is no problem for the first time, the run times wrong again, the reason is: after the first run of excel. Exe is still in process, so this way; If I finish the excel in task manager manually. Exe, and there will be a real time error 462 the remote server does not exist or cannot use,

CodePudding user response:

reference response: 1/f, VB amateurs
first, add a breakpoint newspaper which is in the wrong line,

Second, in the Set excel_App=Nothing advice before closing excel_App object, namely excel_App. Close

If should be excel_App. Quit;

CodePudding user response:

reference milaoshu1020 reply: 3/f
Quote: refer to 1st floor response: VB amateurs

First, add a breakpoint newspaper which is in the wrong line,

Second, in the Set excel_App=Nothing advice before closing excel_App object, namely excel_App. Close

If should be excel_App. Quit;


Yes, is to quit

CodePudding user response:

No, tried a lot of ways

CodePudding user response:

You define the EXCEL object name is xlApp, why finally close into excel_App? Change is good, have a try,

 Private Sub Command1_Click () 
Dim xlApp As New Excel. Application 'definition and create Excel object
Dim xlBook As Excel. The Workbook 'create Workbook
'xlapp. DisplayAlerts=False

XlApp. Visible=True 'to Excel Visible
The Set xlBook=xlApp. Workbooks. Open (App) Path & amp; "/dot. XLS") 'open the Excel template
With xlBook. ActiveSheet
Range (" b4 ")=Text1. Text 'fill the value of the first line of the first column
Range (" i2)=Text2. Text 'fill other ranks the value of the concrete filled position according to the template to do
End With

XlBook. ActiveSheet. Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, the Password:=1234 'table Set close Set excel_Book=excel_App. Workbooks. Open (App) Path & amp; "\ dot. XLS")
ChDir evaluation table cattle technology "D: "
Dim As Long a

XlBook. SaveAs FileName:="evaluation table cattle technology D: \ " & amp; Text1. Text & amp; Text2. Text & amp; ". XLSX ", FileFormat:=_
XlOpenXMLWorkbook CreateBackup:=False

XlApp. Quit
The Set xlApp=Nothing
End Sub

CodePudding user response:

Before running on error resume next kill excel process under
To start your business
  • Related