Results 1 to 6 of 6

Run Time Error '9' - Subscript Out of Range.

Threaded View

  1. #1
    Registered User
    Join Date
    10-09-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    4

    Run Time Error '9' - Subscript Out of Range.

    Hi All,

    I am new to VBA and Excel Programming. I encountered the 'Run Time Error '9' - Subscript Out of Range' error while i tried to load the data. This is existing code. This code was written in Year 2010, I am not sure recent upgrade may causing this error.

    code is
    Private Sub Command32_Click()
    Dim try As Integer
    If Dir(CurrentProject.Path & "\InputData.xls") <> "" Then
     'MsgBox ("Import Process")
       try = 1
     Else
     'MsgBox ("File Does Not exist ")
     Dim MyXL As Object 'Excel Application Object
     Dim XL_File As String
     Dim SheetName As String
    'Dim xlBook As Excel.Workbook
     XL_File = CurrentProject.Path & "\InputData.xls"
     'SheetName = "New Sheet Name"
     'Create the Excel Application Object.
     
     Set MyXL = New Excel.Application
     'Set MyXL = CreateObject("Excel.Application")
    
    'Create new Excel Workbook
     
     'Create the Excel Workbook Object, and open existing Excel Workbook
     
     
    ' Set xlBook = xlApp.Workbooks.Open(XL_File)
          
        MyXL.Workbooks.Add
        
        MyXL.Application.DisplayAlerts = False
        MyXL.Application.Visible = False
        MyXL.Worksheets(1).Name = "Testout"
    
        MyXL.Worksheets(2).Name = "EchimpInventory" ---------------------&&&&&&&&&&&&&&&&&&&&---------- > It is pointing to this line when I tried to debug.
    
    
        MyXL.Worksheets(3).Name = "abendcode"
        MyXL.Worksheets.Add(After:=MyXL.Worksheets(3)).Name = "jobabend"
        MyXL.Worksheets.Add(After:=MyXL.Worksheets(4)).Name = "SCHEDULEDURATION"
        MyXL.Worksheets.Add(After:=MyXL.Worksheets(5)).Name = "jobschedule"
        MyXL.Worksheets.Add(After:=MyXL.Worksheets(6)).Name = "Echimpformatted"
        MyXL.Worksheets.Add(After:=MyXL.Worksheets(7)).Name = "Jobschedtmp"
     
    ' Show the Excel *** in Excel Window.
    'MyXL.Application.Visible = False
    
    'Save the Excel File
    'MyXL.Worksheets(7).SaveAs (XL_File)
    
    MyXL.Workbook.SaveAs (XL_File)
    
    'Close the Workbook or else XL_File will still be open and available for read Only!
    'Or MyXL.Quit could be used instead
    'MyXL.Workbooks(1).Close
    
    'Close the Excel Window and / or Application in background
    'or else XL_File will still be open and available for read Only!
    MyXL.Quit
    
    Set MyXL = Nothing
    Thanks for you help.
    Last edited by alansidman; 10-10-2018 at 12:34 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Run-time error 9 subscript out of range
    By alazar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2018, 10:26 AM
  2. Run time error '9': Subscript out of Range
    By mklindquist0815 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-30-2016, 12:35 PM
  3. [SOLVED] Run-time error '9': subscript out of range - error occurs on multiple computers except one
    By BrettE in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2014, 11:19 PM
  4. Run-time error 9: Subscript out of Range
    By boesingen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-14-2013, 09:41 AM
  5. [SOLVED] Run Time Error 9 - Subscript out of range
    By kushmakarsharma in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-25-2012, 08:02 AM
  6. Run Time Error 9: Subscript Out of Range
    By jason_kelly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2011, 01:44 PM
  7. Run-time error '9': subscript out of range
    By nicko54 in forum Excel General
    Replies: 6
    Last Post: 02-02-2011, 09:08 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1