Results 1 to 6 of 6

"Run-time error '9': Subscript out of range" when referencing between workbooks

Threaded View

  1. #1
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    Office 2010
    Posts
    2

    "Run-time error '9': Subscript out of range" when referencing between workbooks

    Hello,

    I'm developing a more streamlined invoicing system for a friend where information from an invoicing template ("InvoiceTemplate_CompanyName.xlsm") is copied to an excel document summarizing all of their invoices ("InvoiceSummary_CompanyName.xlsx"). I have gotten this to work exactly as I want it on the computer that I've been developing the solution on, but I had an embarrassing moment when trying to transfer the files to my friends computer (i.e., the computer that will end up hosting the excel files). I thought that I would just need to change the path names to those of the new computer, but it did not work. When trying to execute the code, I kept getting a "Run-time error '9': Subscript out of range" error.

    The one thing that I think the problem could be related to is the setup I've been using to develop the VBA solution. I've been using a mac running windows 7 through virtualbox. I've been writing the VBA code in Excel 2010 on the windows side. Like I said, the code worked on my mac (running windows 7), just not on my friends computer. I can't remember, but my friend might have also been running Excel 2013....could there be an issue with my code being developed in Excel 2010?

    Thanks in advance for any advice on this issue!

    Here is the code:

    Sub Invoice_Data_CopyPaste()
    
        Application.ScreenUpdating = False
        
        wsInvoice.Range("H4").Copy 'this worksheet is found in "InvoiceTemplate_CompanyName.xlsm". Users will have this open when code is run 
        
        Dim open_wkb_check As Boolean
        open_wkb_check = IsWorkBookOpen("C:\Users\PathName...\InvoiceSummary_CompanyName.xlsx") 'this calls the function shown below this sub
    
        If open_wkb_check = False Then
            Workbooks.Open ("C:\Users\PathName....\InvoiceSummary_CompanyName.xlsx") 'note path names are not real
        End If
        
        'The code gets hung up at this line (below)
        Workbooks("InvoiceSummary_CompanyName").Worksheets("Invoice Summary List").Range("A3").End(xlDown).Offset(1, 0) _
             .PasteSpecial Paste:=xlPasteValues
    
        Workbooks("InvoiceTemplate_CompanyName").Worksheets("Invoice").Range("H2").Copy
        Workbooks("InvoiceSummary_CompanyName").Worksheets("Invoice Summary List").Range("B3").End(xlDown).Offset(1, 0) _
             .PasteSpecial Paste:=xlPasteValues
    
    '....code continues copying and pasting other values between the two workbooks
    
    End sub

    'This function is used to see if "InvoiceSummary_CompanyName.xlsx" is already open or not.
    Function IsWorkBookOpen(FileName As String)
        Dim ff As Long, ErrNo As Long
    
        On Error Resume Next
        ff = FreeFile()
        Open FileName For Input Lock Read As #ff
        Close ff
        ErrNo = Err
        On Error GoTo 0
    
        Select Case ErrNo
        Case 0:    IsWorkBookOpen = False
        Case 70:   IsWorkBookOpen = True
        Case Else: Error ErrNo
        End Select
    End Function
    Last edited by alansidman; 08-07-2014 at 10:50 PM. Reason: code tags added

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] "run time error 9 subscript out of range" Help?
    By AMV in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-24-2014, 04:54 PM
  2. Replies: 1
    Last Post: 12-15-2011, 10:59 AM
  3. Error msgs: "Object varible or with block variable not set"; "subscript out of range"
    By menyanthe in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-26-2009, 04:58 PM
  4. "Subscript out of range" error for: Workbooks("Test1.xls").Save
    By Just12341234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-2005, 11:05 AM
  5. [SOLVED] FileCopy Command Giving "Subscript Out of Range" Error Message
    By Jim Hagan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2005, 02:05 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