none
VBA range to an external Excel file RRS feed

  • Question

  • I try to range to another Excel file

    The first 4 lines is working ok, but the last is failing

    What is wrong?

    Dim strpath As String

    Dim wb As Workbook

    strpath = "F:\Forsikringsteknik\Person\MVI\VBA\hjælpetabel.xlsx"
       
         Workbooks.Open (strpath)
        Set wb = Workbooks(strpath)

    Hilsen

    Martin

    Thursday, September 15, 2016 5:51 AM

Answers

  • After the file is opened you have to access it throgh either index of Workbooks class or only filename.

    Set wb = Workbooks(Workbooks.Count)

    or

    Set wb = Workbooks("hjælpetabel")


    Best Regards,
    Asadulla Javed, Kolkata
    ---------------------------------------------------------------------------------------------
    Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue.

    Thursday, September 15, 2016 6:58 AM
    Answerer

All replies

  • After the file is opened you have to access it throgh either index of Workbooks class or only filename.

    Set wb = Workbooks(Workbooks.Count)

    or

    Set wb = Workbooks("hjælpetabel")


    Best Regards,
    Asadulla Javed, Kolkata
    ---------------------------------------------------------------------------------------------
    Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue.

    Thursday, September 15, 2016 6:58 AM
    Answerer
  • Hi,

    This is the forum to discuss questions and feedback for Microsoft Excel, I'll move your question to the MSDN forum for Excel

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=exceldev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.


    Regards,
    Emi Zhang
    TechNet Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, September 16, 2016 7:46 AM
  • Please visit Workbook Object (Excel)

    Use Workbooks(index), where index is the workbook name or index number, to return a single Workbook object.

     

    Set wb = Workbooks("hjælpetabel.xlsx")

     

    If you want to use the workbook name as index, please use the full name of the workbook, or you would get the error: out of range.

    Friday, September 16, 2016 9:56 AM
    Moderator
  • thanks a lot
    Thursday, September 22, 2016 11:20 AM