我要使用对话框制作复制粘贴文件,我成功地将数据复制并粘贴到所需的工作表和单元格,但是在VBA出现运行时错误'424'对象必需消息框中。对不起,我是新来的。非常感谢能帮助我们解决问题以及如何解决问题:
hbase.master.loadbalance.bytable
答案 0 :(得分:0)
你需要:
所以而不是:
Set rngDestin = ThisWorkbook.Sheets("RawData").Range("A2").PasteSpecial
这样做:
Set rngDestin = ThisWorkbook.Sheets("RawData").Range("A2")
rngDestin.PasteSpecial
以下是修正后的完整代码,没有任何无用的卷轴:
Sub CopyData()
Dim fileDialog As fileDialog
Dim strPathFile As String
Dim strFileName As String
Dim strPath As String
Dim dialogTitle As String
Dim wbSource As Workbook
Dim rngToCopy As Range
Dim rngRow As Range
Dim rngDestin As Range
Dim lngRowsCopied As Long
dialogTitle = "Navigate to and select required file."
Set fileDialog = Application.fileDialog(msoFileDialogFilePicker)
With fileDialog
.InitialFileName = "P:\Sales & Marketing\REVENUE MANAGEMENT\REPORTS"
'.InitialFileName = ThisWorkbook.Path & "\" 'Alternative to previous line
.AllowMultiSelect = False
.Filters.Clear
.Title = dialogTitle
If .Show = False Then
MsgBox "File not selected to import. Process Terminated"
Exit Sub
End If
strPathFile = .SelectedItems(1)
End With
Set wbSource = Workbooks.Open(Filename:=strPathFile)
Range("16:16,18:18,20:20,22:22,24:24,26:26,28:28,30:30,32:32,34:34,36:36,38:38,40:40,42:42,44:44," & _
"46:46,48:48,50:50,52:52,54:54,56:56,58:58,60:60,62:62,64:64,66:66,68:68,70:70,72:72,74:74" _
).Delete Shift:=xlUp
Range("A15:P45").Copy
Set rngDestin = ThisWorkbook.Sheets("RawData").Range("A2")
rngDestin.PasteSpecial
wbSource.Close SaveChanges:=False
Set fileDialog = Nothing
Set rngRow = Nothing
Set rngToCopy = Nothing
Set wbSource = Nothing
Set rngDestin = Nothing
'MsgBox "The Data Is Imported"
End Sub