dcsimg
Results 1 to 14 of 14

Thread: Runtime error 462 when creating Excel file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2012
    Location
    Essex
    Posts
    261

    Runtime error 462 when creating Excel file

    Hi All

    I am trying to create a excel file in vb6 which does work on a click of the command button but if you click the command button second time i get runtime error 462 "the remote server machine does not exist or is unavailable" i am also trying to terminate excel when finishing using another bit of code, the line in red where it fails the second time.

    Code:
    Private Sub TerminateProcess(app_exe As String)
        Dim Process As Object
        For Each Process In GetObject("winmgmts:").ExecQuery("Select Name from Win32_Process Where Name = '" & app_exe & "'")
            Process.Terminate
        Next
      
    End Sub
    Code:
    Private Sub BoarderButton_Click()
    
    ' CREATE ELECTRICAL BOARDER INFO
    InPro.FontSize = 25
    InPro = "In Progress!!"
    Dim tExcel As Object
    Dim tBook As Object
    Dim tSheet As Object 'Create a new workbook in Excel
    Set tExcel = CreateObject("Excel.Application")
    Set tBook = Excel.Workbooks.Add 'Create an array with 3 columns and 50 rows. You create an array fewer or more columns and rows as needed. For example if your recordset has 5 fields, change the "3" value to "5". If you need more than 50 rows in the new Excel spreadsheet, change the “For r = 1 to 50” statement accordingly.
    Set tSheet = tBook.Worksheets(1)
    tSheet.Range("A1:AJ1").Value = Array("Handle", "Drawing", "Full Path", "(Layout) / Owner Block Name", "Block Name", "F_DWG_NO_1", "DRAW_TTL_L1", "DRAW_TTL_L2", "SHT_TTL_L1", _
    "SHT_TTL_L2", "PLANT", "PL_CD", "DEPT_NO", "OP_NO", "STA_NO", "BT_NO", "DIVISION", "DATE_TTL", "SHT_CUR", "SHT_TOT", "SCALE", "PART_NO", "SHEET_SIZE", "SHEET_TYPE", "ACAD_REL", _
    "CAD_FILE", "DES", "DET", "CHK", "SAF_T", "UCCS", "PO_NO", "V_JOB_NO", "V_NAME", "V_DWG_NO", "REV_NO")
    tSheet.Range("A2:AJ2").Value = Array("2396F", Label13, "S:\DISPENSING PROJECTS" & "Maverick" & "JN" & JNum & " " & "MAVERICK" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00E1" & ELE070 & "" & Label13 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00E1" & ELE070, ShtTitL21, DrawTitL2, Text7, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, Label13, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00E1-" & ELE070 & "-001.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, "APTL", "JN" & JNum & "E", " ")
    tSheet.Range("A3:AJ3").Value = Array("9BF", Label14, "S:\DISPENSING PROJECTS" & "Maverick" & "JN" & JNum & " " & "MAVERICK" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00E1" & ELE070 & "" & Label14 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00E1" & ELE070, ShtTitL21, DrawTitL2, Text8, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, Label14, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00E1-" & ELE070 & "-002.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, "APTL", "JN" & JNum & "E", " ")
    tSheet.Range("A4:AJ4").Value = Array("9BF", Label15, "S:\DISPENSING PROJECTS" & "Maverick" & "JN" & JNum & " " & "MAVERICK" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00E1" & ELE070 & "" & Label15 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00E1" & ELE070, ShtTitL21, DrawTitL2, Text9, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, Label15, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00E1-" & ELE070 & "-003.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, "APTL", "JN" & JNum & "E", " ")
    tSheet.Range("A5:AJ5").Value = Array("9BF", Label16, "S:\DISPENSING PROJECTS" & "Maverick" & "JN" & JNum & " " & "MAVERICK" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00E1" & ELE070 & "" & Label16 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00E1" & ELE070, ShtTitL21, DrawTitL2, Text10, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, Label16, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00E1-" & ELE070 & "-004.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, "APTL", "JN" & JNum & "E", " ")
    tSheet.Range("A6:AJ6").Value = Array("9BF", Label17, "S:\DISPENSING PROJECTS" & "Maverick" & "JN" & JNum & " " & "MAVERICK" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00E1" & ELE070 & "" & Label17 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00E1" & ELE070, ShtTitL21, DrawTitL2, Text11, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, Label17, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00E1-" & ELE070 & "-005.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, "APTL", "JN" & JNum & "E", " ")
    tSheet.Range("A7:AJ7").Value = Array("9BF", Label18, "S:\DISPENSING PROJECTS" & "Maverick" & "JN" & JNum & " " & "MAVERICK" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00E1" & ELE070 & "" & Label18 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00E1" & ELE070, ShtTitL21, DrawTitL2, Text12, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, Label18, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00E1-" & ELE070 & "-006.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, "APTL", "JN" & JNum & "E", " ")
    tBook.SaveAs "S:\DISPENSING PROJECTS" & "Maverick" & "JN" & JNum & " " & "MAVERICK" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\Electrical Boarder Output File.XLSX"
    tExcel.Quit
    TerminateProcess ("EXCEL.exe")
    End Sub
    Regards
    Steve
    Last edited by sbarber007; Feb 13th, 2019 at 06:04 AM.

  2. #2
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,628

    Re: Runtime error 462 when creating Excel file

    Hi Steve

    put this at the end...

    Code:
    Private Sub BoarderButton_Click()
    
    ' CREATE ELECTRICAL BOARDER INFO
    InPro.FontSize = 25
    InPro = "In Progress!!"
    Dim tExcel As Object
    Dim tBook As Object
    Dim tSheet As Object 'Create a new workbook in Excel
    Set tExcel = CreateObject("Excel.Application")
    Set tBook = Excel.Workbooks.Add 'Create an array with 3 columns and 50 rows. You create an array fewer or more columns and rows as needed. For example if your recordset has 5 fields, change the "3" value to "5". If you need more than 50 rows in the new Excel spreadsheet, change the “For r = 1 to 50” statement accordingly.
    Set tSheet = tBook.Worksheets(1)
    tSheet.Range("A1:AJ1").Value = Array("Handle", "Drawing", "Full Path", "(Layout) / Owner Block Name", "Block Name", "F_DWG_NO_1", "DRAW_TTL_L1", "DRAW_TTL_L2", "SHT_TTL_L1", _
    "SHT_TTL_L2", "PLANT", "PL_CD", "DEPT_NO", "OP_NO", "STA_NO", "BT_NO", "DIVISION", "DATE_TTL", "SHT_CUR", "SHT_TOT", "SCALE", "PART_NO", "SHEET_SIZE", "SHEET_TYPE", "ACAD_REL", _
    "CAD_FILE", "DES", "DET", "CHK", "SAF_T", "UCCS", "PO_NO", "V_JOB_NO", "V_NAME", "V_DWG_NO", "REV_NO")
    tSheet.Range("A2:AJ2").Value = Array("2396F", Label13, "S:\DISPENSING PROJECTS" & "Maverick" & "JN" & JNum & " " & "MAVERICK" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00E1" & ELE070 & "" & Label13 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00E1" & ELE070, ShtTitL21, DrawTitL2, Text7, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, Label13, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00E1-" & ELE070 & "-001.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, "APTL", "JN" & JNum & "E", " ")
    tSheet.Range("A3:AJ3").Value = Array("9BF", Label14, "S:\DISPENSING PROJECTS" & "Maverick" & "JN" & JNum & " " & "MAVERICK" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00E1" & ELE070 & "" & Label14 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00E1" & ELE070, ShtTitL21, DrawTitL2, Text8, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, Label14, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00E1-" & ELE070 & "-002.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, "APTL", "JN" & JNum & "E", " ")
    tSheet.Range("A4:AJ4").Value = Array("9BF", Label15, "S:\DISPENSING PROJECTS" & "Maverick" & "JN" & JNum & " " & "MAVERICK" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00E1" & ELE070 & "" & Label15 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00E1" & ELE070, ShtTitL21, DrawTitL2, Text9, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, Label15, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00E1-" & ELE070 & "-003.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, "APTL", "JN" & JNum & "E", " ")
    tSheet.Range("A5:AJ5").Value = Array("9BF", Label16, "S:\DISPENSING PROJECTS" & "Maverick" & "JN" & JNum & " " & "MAVERICK" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00E1" & ELE070 & "" & Label16 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00E1" & ELE070, ShtTitL21, DrawTitL2, Text10, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, Label16, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00E1-" & ELE070 & "-004.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, "APTL", "JN" & JNum & "E", " ")
    tSheet.Range("A6:AJ6").Value = Array("9BF", Label17, "S:\DISPENSING PROJECTS" & "Maverick" & "JN" & JNum & " " & "MAVERICK" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00E1" & ELE070 & "" & Label17 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00E1" & ELE070, ShtTitL21, DrawTitL2, Text11, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, Label17, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00E1-" & ELE070 & "-005.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, "APTL", "JN" & JNum & "E", " ")
    tSheet.Range("A7:AJ7").Value = Array("9BF", Label18, "S:\DISPENSING PROJECTS" & "Maverick" & "JN" & JNum & " " & "MAVERICK" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00E1" & ELE070 & "" & Label18 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00E1" & ELE070, ShtTitL21, DrawTitL2, Text12, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, Label18, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00E1-" & ELE070 & "-006.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, "APTL", "JN" & JNum & "E", " ")
    tBook.SaveAs "S:\DISPENSING PROJECTS" & "Maverick" & "JN" & JNum & " " & "MAVERICK" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\Electrical Boarder Output File.XLSX"
    
    Set tSheet = Nothing
    Set tBook = Nothing
         
    tExcel.Quit
    Set tExcel = Nothing
    
    
    End Sub
    HTH
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2012
    Location
    Essex
    Posts
    261

    Re: Runtime error 462 when creating Excel file

    Mistake
    Last edited by sbarber007; Feb 13th, 2019 at 08:00 AM.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2012
    Location
    Essex
    Posts
    261

    Re: Runtime error 462 when creating Excel file

    Hi ChrisE

    It still seems to come up with same error after second time, i have put below more of the code becuase i am doing one file after another 3 times.

    Code:
    Private Sub BoarderButton_Click()
    
    Dim tExcel As Object
    Dim tBook As Object
    Dim tSheet As Object 'Create a new workbook in Excel
    If Not (tExcel Is Nothing) Then
    
        tExcel.Close (False)
        Set tExcel = Nothing
    
    End If
    
    Set tExcel = New Excel.Application
    Set tExcel = CreateObject("Excel.Application")
    Set tBook = Excel.Workbooks.Add 'Create an array with 3 columns and 50 rows. You create an array fewer or more columns and rows as needed. For example if your recordset has 5 fields, change the "3" value to "5". If you need more than 50 rows in the new Excel spreadsheet, change the “For r = 1 to 50” statement accordingly.
    Set tSheet = tBook.Worksheets(1)
    tSheet.Range("A1:AJ1").Value = Array("Handle", "Drawing", "Full Path", "(Layout) / Owner Block Name", "Block Name", "F_DWG_NO_1", "DRAW_TTL_L1", "DRAW_TTL_L2", "SHT_TTL_L1", _
    "SHT_TTL_L2", "PLANT", "PL_CD", "DEPT_NO", "OP_NO", "STA_NO", "BT_NO", "DIVISION", "DATE_TTL", "SHT_CUR", "SHT_TOT", "SCALE", "PART_NO", "SHEET_SIZE", "SHEET_TYPE", "ACAD_REL", _
    "CAD_FILE", "DES", "DET", "CHK", "SAF_T", "UCCS", "PO_NO", "V_JOB_NO", "V_NAME", "V_DWG_NO", "REV_NO")
    tSheet.Range("A2:AJ2").Value = Array("2396F", EleSheet1, "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00AO" & ELE070 & "" & EleSheet1 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00AO" & ELE070, ShtTitL21, DrawTitL2, Text7, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, EleSheet1, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00AO-" & ELE070 & "-001.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, VendorName, "JN" & JNum & "E")
    tSheet.Range("A3:AJ3").Value = Array("9BF", EleSheet2, "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00AO" & ELE070 & "" & EleSheet2 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00AO" & ELE070, ShtTitL21, DrawTitL2, Text8, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, EleSheet2, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00AO-" & ELE070 & "-002.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, VendorName, "JN" & JNum & "E", " ")
    tSheet.Range("A4:AJ4").Value = Array("9BF", EleSheet3, "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00AO" & ELE070 & "" & EleSheet3 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00AO" & ELE070, ShtTitL21, DrawTitL2, Text9, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, EleSheet3, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00AO-" & ELE070 & "-003.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, VendorName, "JN" & JNum & "E", " ")
    tSheet.Range("A5:AJ5").Value = Array("9BF", EleSheet4, "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00AO" & ELE070 & "" & EleSheet4 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00AO" & ELE070, ShtTitL21, DrawTitL2, Text10, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, EleSheet4, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00AO-" & ELE070 & "-004.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, VendorName, "JN" & JNum & "E", " ")
    tSheet.Range("A6:AJ6").Value = Array("9BF", EleSheet5, "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00AO" & ELE070 & "" & EleSheet5 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00AO" & ELE070, ShtTitL21, DrawTitL2, Text11, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, EleSheet5, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00AO-" & ELE070 & "-005.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, VendorName, "JN" & JNum & "E", " ")
    tSheet.Range("A7:AJ7").Value = Array("9BF", EleSheet6, "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00AO" & ELE070 & "" & EleSheet6 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00AO" & ELE070, ShtTitL21, DrawTitL2, Text12, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, EleSheet6, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00AO-" & ELE070 & "-006.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, VendorName, "JN" & JNum & "E", " ")
    tBook.SaveAs "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\Electrical Boarder Output File.XLSX"
    Set tBook = Nothing
    Set tSheet = Nothing
    
    tExcel.Quit
    Set tExcel = Nothing
    
    Timer4.Enabled = True
    End Sub
    
    Private Sub Timer4_Timer()
    Dim tExcel As Object
    Dim tBook As Object
    Dim tSheet As Object 'Create a new workbook in Excel
    If Not (tExcel Is Nothing) Then
    
        tExcel.Close (False)
        Set tExcel = Nothing
    
    End If
    Set tExcel = New Excel.Application
    Set tExcel = CreateObject("Excel.Application")
    Set tBook = Excel.Workbooks.Add 'Create an array with 3 columns and 50 rows. You create an array fewer or more columns and rows as needed. For example if your recordset has 5 fields, change the "3" value to "5". If you need more than 50 rows in the new Excel spreadsheet, change the “For r = 1 to 50” statement accordingly.
    Set tSheet = tBook.Worksheets(1)
    tSheet.Range("A1:AJ1").Value = Array("Handle", "Drawing", "Full Path", "(Layout) / Owner Block Name", "Block Name", "F_DWG_NO_1", "DRAW_TTL_L1", "DRAW_TTL_L2", "SHT_TTL_L1", _
    "SHT_TTL_L2", "PLANT", "PL_CD", "DEPT_NO", "OP_NO", "STA_NO", "BT_NO", "DIVISION", "DATE_TTL", "SHT_CUR", "SHT_TOT", "SCALE", "PART_NO", "SHEET_SIZE", "SHEET_TYPE", "ACAD_REL", _
    "CAD_FILE", "DES", "DET", "CHK", "SAF_T", "UCCS", "PO_NO", "V_JOB_NO", "V_NAME", "V_DWG_NO", "REV_NO")
    tSheet.Range("A2:AJ2").Value = Array("2396F", PNUSheet1, "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00AO" & PNEU070 & "" & PNUSheet1 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00AO" & PNEU070, ShtTitL22, DrawTitL2, Text13, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, PNUSheet1, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00AO-" & PNEU070 & "-001.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, VendorName, "JN" & JNum & "P", " ")
    tSheet.Range("A3:AJ3").Value = Array("9BF", PNUSheet2, "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00AO" & PNEU070 & "" & PNUSheet2 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00AO" & PNEU070, ShtTitL22, DrawTitL2, Text14, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, PNUSheet2, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00AO-" & PNEU070 & "-002.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, VendorName, "JN" & JNum & "P", " ")
    tSheet.Range("A4:AJ4").Value = Array("9BF", PNUSheet3, "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00AO" & PNEU070 & "" & PNUSheet3 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00AO" & PNEU070, ShtTitL22, DrawTitL2, Text15, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, PNUSheet3, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00AO-" & PNEU070 & "-003.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, VendorName, "JN" & JNum & "P", " ")
    tSheet.Range("A5:AJ5").Value = Array("9BF", PNUSheet4, "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00AO" & PNEU070 & "" & PNUSheet4 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00AO" & PNEU070, ShtTitL22, DrawTitL2, Text16, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, PNUSheet4, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00AO-" & PNEU070 & "-004.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, VendorName, "JN" & JNum & "P", " ")
    tSheet.Range("A6:AJ6").Value = Array("9BF", PNUSheet5, "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00AO" & PNEU070 & "" & PNUSheet5 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00AO" & PNEU070, ShtTitL22, DrawTitL2, Text17, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, PNUSheet5, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00AO-" & PNEU070 & "-005.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, VendorName, "JN" & JNum & "P", " ")
    tSheet.Range("A7:AJ7").Value = Array("9BF", PNUSheet6, "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\070ZE\00AO" & PNEU070 & "" & PNUSheet6 & ".DWG", "(Model)", "SHEET2_A2MR1", "070ZE00AO" & PNEU070, ShtTitL22, DrawTitL2, Text18, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, PNUSheet6, TotalEleSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "070ZE-00AO-" & PNEU070 & "-006.DWG", EleDesignBy, EleDetailBy, EleCheckedBy, " ", UCCS, PONum, "JN" & JNum, VendorName, "JN" & JNum & "P", " ")
    tBook.SaveAs "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\Pneumatic Boarder Output File.XLSX"
    Set tSheet = Nothing
    Set tBook = Nothing
         
    tExcel.Quit
    Set tExcel = Nothing
    Timer4.Enabled = False
    Timer6.Enabled = True
    End Sub
    
    Private Sub Timer6_Timer()
    Dim tExcel As Object
    Dim tBook As Object
    Dim tSheet As Object 'Create a new workbook in Excel
    Set tExcel = New Excel.Application
    Set tExcel = CreateObject("Excel.Application")
    Set tBook = Excel.Workbooks.Add 'Create an array with 3 columns and 50 rows. You create an array fewer or more columns and rows as needed. For example if your recordset has 5 fields, change the "3" value to "5". If you need more than 50 rows in the new Excel spreadsheet, change the “For r = 1 to 50” statement accordingly.
    Set tSheet = tBook.Worksheets(1)
    tSheet.Range("A1:AI1").Value = Array("Handle", "Drawing", "Full Path", "(Layout) / Owner Block Name", "Block Name", "F_DWG_NO_1", "DRAW_TTL_L1", "DRAW_TTL_L2", "SHT_TTL_L1", _
    "SHT_TTL_L2", "PLANT", "PL_CD", "DEPT_NO", "OP_NO", "STA_NO", "BT_NO", "DIVISION", "DATE_TTL", "SHT_CUR", "SHT_TOT", "SCALE", "PART_NO", "SHEET_SIZE", "SHEET_TYPE", "ACAD_REL", _
    "CAD_FILE", "DES", "DET", "CHK", "SAF_T", "UCCS", "PO_NO", "V_JOB_NO", "V_NAME", "V_DWG_NO")
    tSheet.Range("A2:AI2").Value = Array("2396F", ECPLSheet1, "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\131ZE\00AO" & ECPL131 & "" & ECPLSheet1 & ".DWG", "(Model)", "SHEET1_A2MR1", "131ZE00AO" & ECPL131, ShtTitL23, DrawTitL2, ECPLSH1, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, ECPLSheet1, TotalECPLSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "131ZE-00AO-" & ECPL131 & "-001.DWG", ECPLDesignedBy, ECPLDetailBy, ECPLCheckedBy, " ", UCCS, PONum, "JN" & JNum, VendorName, "JN" & JNum & "ECPL")
    tSheet.Range("A3:AI3").Value = Array("2396F", ECPLSheet2, "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\131ZE\00AO" & ECPL131 & "" & ECPLSheet2 & ".DWG", "(Model)", "SHEET1_A2MR1", "131ZE00AO" & ECPL131, ShtTitL23, DrawTitL2, ECPLSH2, DrawTitL1, Plant, PlantCode, DeptNum, OPNo, OPNo, BTNum, "ENGINE", Date, ECPLSheet2, TotalECPLSh, ElePnuScale, " ", "A2", "DETAIL", "2013", "131ZE-00AO-" & ECPL131 & "-002.DWG", ECPLDesignedBy, ECPLDetailBy, ECPLCheckedBy, " ", UCCS, PONum, "JN" & JNum, VendorName, "JN" & JNum & "ECPL")
    tBook.SaveAs "S:\DISPENSING PROJECTS" & "FOX" & "JN" & JNum & " " & "FOX" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\ECPL Boarder Output File.XLSX"
    Set tSheet = Nothing
    Set tBook = Nothing
         
    tExcel.Quit
    Set tExcel = Nothing
    TerminateProcess ("EXCEL.exe")
    Timer6.Enabled = False
    End Sub
    Last edited by sbarber007; Feb 13th, 2019 at 08:03 AM.

  5. #5
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,312

    Re: Runtime error 462 when creating Excel file

    To start instead of duplicating the code in each Event, place it in a subroutine and use some parameters to differentiate in what you need to do.
    Then make sure the subroutine is not called from a Timer event when the routine has not finished yet.

    Also this part makes no sense, because these are local variables which have not been initialized yet
    Code:
    Dim tExcel As Object
    
    '
    ' tExcel is Nothing, because it's a local variable!
    '
    If Not (tExcel Is Nothing) Then
        tExcel.Close (False)
        Set tExcel = Nothing
    End If
    Last edited by Arnoutdv; Feb 13th, 2019 at 08:14 AM.

  6. #6
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,628

    Re: Runtime error 462 when creating Excel file

    Hi,

    strange way of doing this, where does the Data come from?

    I saw this...
    Code:
    Set tBook = Excel.Workbooks.Add
    the t is missing
    Code:
    Set tBook = tExcel.Workbooks.Add
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,069

    Re: Runtime error 462 when creating Excel file

    You're not closing your workbook.

    Code:
    tBook.SaveAs "S:\DISPENSING PROJECTS" & "Maverick" & "JN" & JNum & " " & "MAVERICK" & " " & DrawTitL1 & " DISPENSING SYSTEMS" & " OP " & OPNo & "\DRAWINGS\Electrical Boarder Output File.XLSX"
    
    
    tBook.Close
    tExcel.Quit
    
    Set tSheet = Nothing
    Set tBook = Nothing 
    Set tExcel = Nothing
    Doing that, you shouldn't need the terminate process routine.

    Also... and I'll admit, it's been a long time since I've done Excel automation, so I may be wrong about this... but this doesn't look right to begin with:
    Code:
    Set tBook = Excel.Workbooks.Add
    Are you sure that's supposed to be Excel and tExcel? For some reason I want to say that you should be using the instance of the Excel application object you just created. But I don't know that for sure and I don't have a way to test it for sure, so I could be wrong.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,312

    Re: Runtime error 462 when creating Excel file

    Also note this:
    Code:
    Set tExcel = New Excel.Application
    Set tExcel = CreateObject("Excel.Application")
    Either choose the first method or the second, but not both.
    This leaves multiple Excel instances running...

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2012
    Location
    Essex
    Posts
    261

    Re: Runtime error 462 when creating Excel file

    HI all

    thanks for your help that great all working, But i got a simlar problem with another part of the code below which also fails the second time i tried putting set nothing statements in but i failed this one comes
    up with runtime error 91 "Object variable or with block variable not set

    Code:
    Private Sub Command3_Click()
      If Dir("S:\DISPENSING PROJECTS" & "Maverick" & "JN" & MaverickDisp.JNum & " " & "MAVERICK" & " " & MaverickDisp.DrawTitL1 & " " & "DISPENSING SYSTEMS" & " " & "OP" & " " & MaverickDisp.OPNo & "\DRAWINGS" & "TITLES.xlsx") <> "" Then
    Dim r As Integer
       Dim xl As Excel.Application
       Dim var As Variant
       Set xl = CreateObject("excel.Application")
       xl.Workbooks.Open ("S:\DISPENSING PROJECTS" & "Maverick" & "JN" & MaverickDisp.JNum & " " & "MAVERICK" & " " & MaverickDisp.DrawTitL1 & " " & "DISPENSING SYSTEMS" & " " & "OP" & " " & MaverickDisp.OPNo & "\DRAWINGS\TITLES.xlsx")
       xl.Sheets("JTB BatchAttEdit").Select
       xl.Visible = False
    '   var = INFO.Text
     ActiveSheet.Range("A2", "W31").Select
       Text1.Text = ActiveSheet.Range("W2")
       Text2.Text = ActiveSheet.Range("W3")
       Text3.Text = ActiveSheet.Range("W4")
       Text4.Text = ActiveSheet.Range("W5")
       Text5.Text = ActiveSheet.Range("W6")
       Text6.Text = ActiveSheet.Range("W7")
       Text7.Text = ActiveSheet.Range("W8")
       Text8.Text = ActiveSheet.Range("W9")
       Text9.Text = ActiveSheet.Range("W10")
       Text10.Text = ActiveSheet.Range("W11")
       Text11.Text = ActiveSheet.Range("W12")
       Text12.Text = ActiveSheet.Range("W13")
       Text13.Text = ActiveSheet.Range("W14")
       Text14.Text = ActiveSheet.Range("W15")
       Text15.Text = ActiveSheet.Range("W16")
       Text16.Text = ActiveSheet.Range("W17")
       Text17.Text = ActiveSheet.Range("W18")
       Text18.Text = ActiveSheet.Range("W19")
       Text19.Text = ActiveSheet.Range("W20")
       Text20.Text = ActiveSheet.Range("W21")
       Text21.Text = ActiveSheet.Range("W22")
       Text22.Text = ActiveSheet.Range("W23")
       Text23.Text = ActiveSheet.Range("W24")
       Text24.Text = ActiveSheet.Range("W25")
       Text25.Text = ActiveSheet.Range("W26")
       Text26.Text = ActiveSheet.Range("W27")
       Text27.Text = ActiveSheet.Range("W28")
       Text28.Text = ActiveSheet.Range("W29")
       Text29.Text = ActiveSheet.Range("W30")
       Text30.Text = ActiveSheet.Range("W31")
       Combo1.Text = ActiveSheet.Range("K2")
       Combo2.Text = ActiveSheet.Range("K3")
       Combo3.Text = ActiveSheet.Range("K4")
       Combo4.Text = ActiveSheet.Range("K5")
       Combo5.Text = ActiveSheet.Range("K6")
       Combo6.Text = ActiveSheet.Range("K7")
       Combo7.Text = ActiveSheet.Range("K8")
       Combo8.Text = ActiveSheet.Range("K9")
       Combo9.Text = ActiveSheet.Range("K10")
       Combo10.Text = ActiveSheet.Range("K11")
       Combo11.Text = ActiveSheet.Range("K12")
       Combo12.Text = ActiveSheet.Range("K13")
       Combo13.Text = ActiveSheet.Range("K14")
       Combo14.Text = ActiveSheet.Range("K15")
       Combo15.Text = ActiveSheet.Range("K16")
       Combo16.Text = ActiveSheet.Range("K17")
       Combo17.Text = ActiveSheet.Range("K18")
       Combo18.Text = ActiveSheet.Range("K19")
       Combo19.Text = ActiveSheet.Range("K20")
       Combo20.Text = ActiveSheet.Range("K21")
       Combo21.Text = ActiveSheet.Range("K22")
       Combo22.Text = ActiveSheet.Range("K23")
       Combo23.Text = ActiveSheet.Range("K24")
       Combo24.Text = ActiveSheet.Range("K25")
       Combo25.Text = ActiveSheet.Range("K26")
       Combo26.Text = ActiveSheet.Range("K27")
       Combo27.Text = ActiveSheet.Range("K28")
       Combo28.Text = ActiveSheet.Range("K29")
       Combo29.Text = ActiveSheet.Range("K30")
       Combo30.Text = ActiveSheet.Range("K31")
       xl.ActiveWorkbook.Close
       xl.Application.Quit
    Set xl.Sheets = Nothing
    Set xl.ActiveWorkbook = Nothing
    Set xl.Application = Nothing
     
          Else
          MsgBox "File Does Not Exist Use JTB BatchAttEdit in Autocad to Create File."
          
          End If
          
    End Sub
    Regards
    Steve
    Last edited by sbarber007; Feb 14th, 2019 at 02:49 AM.

  10. #10
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,312

    Re: Runtime error 462 when creating Excel file

    ActiveSheet is an internal Excel reference, not a reference of your own.
    You have to make explicit references.
    Code:
    Dim xlSheet As Excel.Sheet
    
    Set xlSheet = xl.Sheets("JTB BatchAttEdit")
    
    ' Now replace all ActiveSheet. with xlSheet.
    
    Set xlSheet = Nothing

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2012
    Location
    Essex
    Posts
    261

    Re: Runtime error 462 when creating Excel file

    @Arnoutdv

    Hi
    Thanks for your reply

    I have tried your post #10 but i get Compile Error: User-defined type not defined on the line in red below.


    Code:
    Private Sub Command3_Click()
    If Dir("S:\DISPENSING PROJECTS\" & "Fox\" & "JN" & FoxDisp.JNum & " " & "Fox" & " " & FoxDisp.DrawTitL1 & " " & "DISPENSING SYSTEMS" & " " & "OP" & " " & FoxDisp.OPNo & "\DRAWINGS\" & "TITLES.xlsx") <> "" Then
    
    Dim r As Integer
       Dim xl As Excel.Application
       Dim xlSheet As Excel.Sheet
       Dim var As Variant
       Set xl = CreateObject("excel.Application")
       xl.Workbooks.Open ("S:\DISPENSING PROJECTS\" & "Fox\" & "JN" & FoxDisp.JNum & " " & "FOX" & " " & FoxDisp.DrawTitL1 & " " & "DISPENSING SYSTEMS" & " " & "OP" & " " & FoxDisp.OPNo & "\DRAWINGS\TITLES.xlsx")
       Set xlSheet = xl.Sheets("JTB BatchAttEdit")
       xl.Visible = False
      ' var = INFO.Text
       ' xlSheet.Range("A2", "W31").Select
       xlSheet.Range("A2", "W31").Select
       Text1.Text = xlSheet.Range("W2")
       Text2.Text = xlSheet.Range("W3")
       Text3.Text = xlSheet.Range("W4")
       Text4.Text = xlSheet.Range("W5")
       Text5.Text = xlSheet.Range("W6")
       Text6.Text = xlSheet.Range("W7")
       Text7.Text = xlSheet.Range("W8")
       Text8.Text = xlSheet.Range("W9")
       Text9.Text = xlSheet.Range("W10")
       Text10.Text = xlSheet.Range("W11")
       Text11.Text = xlSheet.Range("W12")
       Text12.Text = xlSheet.Range("W13")
       Text13.Text = xlSheet.Range("W14")
       Text14.Text = xlSheet.Range("W15")
       Text15.Text = xlSheet.Range("W16")
       Text16.Text = xlSheet.Range("W17")
       Text17.Text = xlSheet.Range("W18")
       Text18.Text = xlSheet.Range("W19")
       Text19.Text = xlSheet.Range("W20")
       Text20.Text = xlSheet.Range("W21")
       Text21.Text = xlSheet.Range("W22")
       Text22.Text = xlSheet.Range("W23")
       Text23.Text = xlSheet.Range("W24")
       Text24.Text = xlSheet.Range("W25")
       Text25.Text = xlSheet.Range("W26")
       Text26.Text = xlSheet.Range("W27")
       Text27.Text = xlSheet.Range("W28")
       Text28.Text = xlSheet.Range("W29")
       Text29.Text = xlSheet.Range("W30")
       Text30.Text = xlSheet.Range("W31")
       Combo1.Text = xlSheet.Range("K2")
       Combo2.Text = xlSheet.Range("K3")
       Combo3.Text = xlSheet.Range("K4")
       Combo4.Text = xlSheet.Range("K5")
       Combo5.Text = xlSheet.Range("K6")
       Combo6.Text = xlSheet.Range("K7")
       Combo7.Text = xlSheet.Range("K8")
       Combo8.Text = xlSheet.Range("K9")
       Combo9.Text = xlSheet.Range("K10")
       Combo10.Text = xlSheet.Range("K11")
       Combo11.Text = xlSheet.Range("K12")
       Combo12.Text = xlSheet.Range("K13")
       Combo13.Text = xlSheet.Range("K14")
       Combo14.Text = xlSheet.Range("K15")
       Combo15.Text = xlSheet.Range("K16")
       Combo16.Text = xlSheet.Range("K17")
       Combo17.Text = xlSheet.Range("K18")
       Combo18.Text = xlSheet.Range("K19")
       Combo19.Text = xlSheet.Range("K20")
       Combo20.Text = xlSheet.Range("K21")
       Combo21.Text = xlSheet.Range("K22")
       Combo22.Text = xlSheet.Range("K23")
       Combo23.Text = xlSheet.Range("K24")
       Combo24.Text = xlSheet.Range("K25")
       Combo25.Text = xlSheet.Range("K26")
       Combo26.Text = xlSheet.Range("K27")
       Combo27.Text = xlSheet.Range("K28")
       Combo28.Text = xlSheet.Range("K29")
       Combo29.Text = xlSheet.Range("K30")
       Combo30.Text = xlSheet.Range("K31")
       xl.ActiveWorkbook.Close
       xl.Application.Quit
    
    Set xlSheet = Nothing
          
          Else
          MsgBox "File Does Not Exist Use JTB BatchAttEdit in Autocad to Create File."
          
          End If
    
    End Sub
    Regards
    Steve

  12. #12
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,312

    Re: Runtime error 462 when creating Excel file

    I haven't checked it, but maybe it's:
    Code:
    Dim xlSheet As Excel.WorkSheet
    It seems to me you are using all kind of code fragments found on the internet.
    Your naming convention is not consistent and you are mixing early-bound (xlExcel As Excel.Application) and late-bound (xlExcel As Object).
    Better clean this up first

  13. #13
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,628

    Re: Runtime error 462 when creating Excel file

    Hi 007

    well you are certainly trying, why not use a Flexgrid rather than Textboxes?
    it will be far better for Exporting to Excel

    here a sample filling a Flex

    Code:
    Private Sub Command1_Click()
    'Fill Grid with some Data
       Dim i As Long, j As Long
          With MSFlexGrid1
             .Rows = 5
             .Cols = 30
             .FixedRows = 1
             .FixedCols = 0
             .Clear
             For j = 0 To .Cols - 1
                .TextMatrix(0, j) = "Column " & j
             Next
             For i = 1 To .Rows - 1
                For j = 0 To .Cols - 1
                   .TextMatrix(i, j) = "Cell " & i & "." & j
                Next
             Next
          End With
    End Sub
    say if this would be better or not
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2012
    Location
    Essex
    Posts
    261

    Re: Runtime error 462 when creating Excel file

    @Arnoutdv

    Thanks All Good Now

    @ChrisE
    I will give that ago thanks

    regard

    steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width