具有常量文件路径的变量文件名的excel宏

时间:2017-06-06 00:13:04

标签: excel-vba vba excel

我需要将数据从源码复制到我的表格。我有代码:

WbPath = ThisWorkbook.Path SFile ='这里我需要输入消息来选择一个excel文件....

谢谢你。

Sub Get_Data()

    Application.ScreenUpdating = False

    Dim SCFile As Variant
    Dim Cfndr As String
    Dim WbPath  As String
    Dim SFile   As String


    ThisWorkbook.Activate
        'start in THIS workbook
    Sheets("Code_Finder").Select
        'switch to data import sheet

        'Opens source file (this filepath never changes so...)
        WbPath = ThisWorkbook.Path
        SFile = 'here i need an input message to pick an excel file....

    SCFile = Application.GetOpenFilename
        'Workbooks.Open Filename:="\\ac3app01\T1\WATER NSW FINANCE & PRICING\EBROWN\Code finder\Code Finder_Test.xlsx", ReadOnly:=True
    Workbooks.Open SCFile, ReadOnly:=True
        'Workbooks("Code Finder_Test.xlxs").Activate 'switch to source workbook

       Cfndr = ActiveWorkbook.Name

    Sheets("Active Project Codes").Select
        'switch to source data sheet
    [a1].CurrentRegion.Copy
        'Copy data to clipboard

    ThisWorkbook.Activate
        'Return to THIS workbook

    [a1].PasteSpecial Paste:=xlPasteValues
        'paste data to import start cell
    Range("A1").Copy
        'cancels highlighted paste region

    Workbooks(Cfndr).Close SaveChanges:=False

'Call FinalReport

    Application.ScreenUpdating = True


End Sub

0 个答案:

没有答案