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,