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
Bookmarks