最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

excel - How do I Assign File path to this VBA code - Stack Overflow

programmeradmin1浏览0评论

I'm trying to learn VBA and have this code that lets me pick a file. It opens to the basic folder, but I want it to open a specific folder 1st before I choose my file from there. I've tried a few things I saw online & ChatGPT, but nothing has worked.

Sub Get_Data_From_File()  
    Dim FileToOpen As Variant  
    Dim OpenBook As Workbook

    Application.ScreenUpdating = False

    FileToOpen = Application.GetOpenFilename(Title:="Browse for your file & Import Range", FileFilter:="Excel Files(*.xlsx*),*xlsx*")
    If FileToOpen <> False Then    
        Set OpenBook = Application.Workbooks.Open(FileToOpen)    
        ThisWorkbook.Worksheets("Dec").Range("F3").Value =  OpenBook.Sheets("Product Totals").Range("D181").Value * 1    
        ThisWorkbook.Worksheets("Dec").Range("F4").Value = OpenBook.Sheets("PL").Range("C6").Value
        OpenBook.Close False
    End If
    
    Application.ScreenUpdating = True
End Sub
发布评论

评论列表(0)

  1. 暂无评论