我正在尝试构建一个宏,在运行时将允许我选择给定的文件并检查该选定文件的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
答案 0 :(得分: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