0

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

我拼凑了下面的代码,将任何给定选定文件的 C 列中的数据填充到宏文件的 A 列中,从我可以通过搜索站点拼凑的内容,但在选择文件后我仍然收到错误 400运行此 Sub 时打开。将不胜感激找出这部分的任何帮助。

谢谢!

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
4

1 回答 1

1

您在工作簿之间导航的方式似乎存在问题,请尝试以下操作:

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
于 2015-02-16T18:27:31.897 回答