从选定的 excel 文件复制数据

Copy data from a selected excel file

我正在尝试构建一个宏,当 运行 时将允许我 select 给定文件并检查该 selected 文件的 C 列中的数据。我是 VBA 的新手,只有基本的技能。除了我从变量文件中提取数据并将其粘贴到宏文件的 A 列以执行审查功能的部分之外,我的代码的所有部分都在工作。

我拼凑了以下代码,将任何给定 selected 文件的 C 列中的数据填充到宏文件的 A 列中,这些数据是我通过搜索网站拼凑出来的,但我select打开文件后,运行打开此 Sub,我仍然收到错误 400。如果您能协助解决这部分问题,我们将不胜感激。

谢谢!

Sub PopulateUploaderFunds()
'Pull in funds from uploader to be reviewed for custody and mirror accounts
Dim uploadfile As Variant
Dim uploader As Workbook
MsgBox ("Please select uploader file to be reviewed")
uploadfile = Application.GetOpenFilename()
If uploadfile = "False" Then
Exit Sub
End If
Workbooks.Open uploadfile
Set uploader = ActiveWorkbook
With uploader
    Application.CutCopyMode = False
    Range("C1").End(xlDown).Select
    Selection.Copy
End With
Windows("Test Mirror Macro Build Test.xlsm").Activate
Sheets("Sheet1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
End Sub

您在工作簿之间导航的方式似乎有问题,试试这个:

Sub PopulateUploaderFunds()
'Pull in funds from uploader to be reviewed for custody and mirror accounts
Dim uploadfile As Variant
Dim uploader As Workbook
Dim CurrentBook As Workbook

Set CurrentBook = ActiveWorkbook
MsgBox ("Please select uploader file to be reviewed")
uploadfile = Application.GetOpenFilename()
    If uploadfile = "False" Then
        Exit Sub
    End If
Workbooks.Open uploadfile
Set uploader = ActiveWorkbook
With uploader
    Application.CutCopyMode = False
    Range("C:C").Copy
End With
CurrentBook.Activate
Sheets("Sheet1").Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
End Sub