VBA Workbook.Open(File) returns Nothing

后端 未结 2 1002
清酒与你
清酒与你 2020-12-22 10:54

EDIT: After lots of help and not having a clue what\'s going on, it worked using a different method of opening (see @JohnMuggin\'s help below)--so I un-

相关标签:
2条回答
  • 2020-12-22 11:23

    And at the very last try this little sub. If it doesn't open your workbook then there is a problem with the path or filename

    Sub opendfghj()
    
    Dim wb As Workbook
    
    Workbooks.Open Filename:="C:\Users\User\Desktop\Templates and Example data\Repeat Tests\file.xlsx"
    
    Set wb = ActiveWorkbook
    
    wb.Worksheets("Sheet1").Range("A1") = "It Works"
    End Sub
    
    0 讨论(0)
  • 2020-12-22 11:39

    If you have a copy of the workbook open (in a different folder) with the same name as the one your VBA is trying to open, it fails silently. The ActiveWorkbook solution appears to work - as you have at least one workbook open already - and that is active - but its not the one you think it is.

    I imagine it it could be a common mistake - as while developing a VBA project you might have a copy of the target workbook open to check on column numbers etc.

    0 讨论(0)
提交回复
热议问题