使用Excel 365中的VBA复制从CSV到XLSX文件的数据
我正在尝试创建一个宏,将所有数据从CSV文件复制到执行宏的工作簿。
中获得了以下代码
我从
我已经用.csv,.xlsx文件对此进行了测试;以及表名称和数字的组合。
我怀疑它找不到当前的工作簿,因为我已经将Marco保存到了个人宏观文件Excel生成。
有人可以建议我如何纠正粘贴位置吗?
Sub AS_and_L_Reports()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Application.ScreenUpdating = False
FileToOpen = Application.GetOpenFilename
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets(1).Range("A1:P20").Copy
ThisWorkbook.Worksheets(1).Range("A1").PasteSpecial xlPasteValues
OpenBook.Close True
End If
Application.ScreenUpdating = True
End Sub
I am trying to create a macro that copies all the data from a csv file to the workbook that executed the macro.
I got the code below from this Youtube video
It appears to copy, but fails to paste.
I have tested this with .csv, .xlsx files; and combinations of sheet names and numbers.
I suspect it can't find the current workbook, because I have save the Marco to the Personal Macro file excel generates.
Can someone please advise how I can correct the paste location?
Sub AS_and_L_Reports()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Application.ScreenUpdating = False
FileToOpen = Application.GetOpenFilename
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets(1).Range("A1:P20").Copy
ThisWorkbook.Worksheets(1).Range("A1").PasteSpecial xlPasteValues
OpenBook.Close True
End If
Application.ScreenUpdating = True
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论