none
Using VBA to Open Filename RRS feed

  • Question

  • I am attempting to open a workbook that has been assigned a range name, copy a sheet form that same workbook that has been assigned a range name, and paste that sheet into another workbook. However, the code I am using does not work.

    Here's the code below:

    ' Open StartDate & EndDate files

    Sub OpenDataFiles()   

        Dim iFpathStart As Variant

        Dim iFpathEnd As Variant

        Dim iFileLocationStart As Variant
        Dim iFileLocationEnd As Variant
        Dim inputSheetStart As Variant
        Dim inputSheetEnd As Variant
        Dim outputFname As Variant
        
        iFileLocationStart = Range("I11").Value
        iFileLocationEnd = Range("I12").Value
        iFNameStart = Range("I9").Value
        iFNameEnd = Range("I10").Value
        inputSheetStart = Range("I13").Value
        inputSheetEnd = Range("I14").Value
        outputFname = Range("I15").Value
        
        Workbooks.Open Filename:=iFpathStart
        'Workbooks.Open Filename:=iFpathEnd
        
     ' Copying AGL Output from Start & End Dates to Attribution Report Workbook
            
        Windows(iFNameStart).Activate
        Sheets(inputSheetStart).Select
        Cells.Select
        Selection.Copy
        Windows(outputFname).Activate
        Sheets.Add After:=ActiveSheet
        Cells.Select
        ActiveSheet.Paste

    What am i doing wrong?

    Thanks!

    Wednesday, April 19, 2017 5:59 PM

All replies

  • You try to open a file with path/filename iFpathStart, but you don't assign any value to iFpathStart

    Perhaps (just guessing here)

    iFpathStart = iFileLocationStart & "\" & iFNameStart

    just above the line that opens iFNameStart?


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Wednesday, April 19, 2017 7:40 PM
  • That was it!! THanks.
    Wednesday, April 19, 2017 8:12 PM