VBA打开工作簿并复制内容

VBA打开工作簿并复制内容

本文介绍了Excel VBA打开工作簿并复制内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个VBA,它应该要求用户进行文件,然后复制第一个工作表的内容(工作表名称不是默认的,并且包含一个空格)。之后,我需要删除特定的列。从行我需要删除包含特定文本的行(案例密集型)

I'm creating a VBA that should ask user for file, then copy the content of the first sheet (Sheet name is not the default and contains a space) .. After that I need to delete specific columns .. From the rows I need to delete the rows that contains specific text (Case intensive)

现在我可以做的是加载文件,但不知道如何复制数据到活动工作表!!

All I can do now is load the file, but don't know how to copy the data to the active worksheet!!

FileToOpen = Application.GetOpenFilename _
(Title:="Please Choose the RTCM File", _
FileFilter:="Excel Files *.xls (*.xls),")
''
If FileToOpen = False Then
MsgBox "No file specified.", vbExclamation, "Duh!!!" ' Notification that nothing is chosen
Exit Sub
Else ' Load the file, copy the first sheet and paste it in active sheet ...

End If


推荐答案

希望这有帮助。此代码将粘贴已被激活的工作表中的数据。如果要在特定工作表中粘贴数据,则可以使用工作表替换活动表(Sheetname)。

Hope this helps. This code will paste data in the sheet that is already active. you can replace Activesheet with Sheets("Sheetname") if you want to paste data in a specific sheet.

我认为粘贴的数据只能从列A到列Z,请根据需要进行更改。

I have assumed that the data being pasted will only be from column A to column Z, please change it as required.

FileToOpen = Application.GetOpenFilename _
(Title:="Please Choose the RTCM File", _
FileFilter:="Excel Files *.xls (*.xls),")

If FileToOpen = False Then
    MsgBox "No file specified.", vbExclamation, "Duh!!!" ' Notification that nothing is chosen
    Exit Sub
Else ' Load the file, copy the first sheet and paste it in active sheet ...
    ThisWorkbook.Activate
    ThisWorkbook.ActiveSheet.Range("A1:Z65536").ClearContents
    Workbooks(FileToOpen).Activate
    lrow=Workbooks(FileToOpen).Sheets("Sheet1").Cells(65536,1).End(xlUp).Row
    Workbooks(FileToOpen).Sheets("Sheet1").Range("A1:Z" & lrow).Copy
    ThisWorkbook.Activate
    ThisWorkbook.ActiveSheet.Range("A1").PasteSpecial xlPasteValues
End If

这篇关于Excel VBA打开工作簿并复制内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 22:17