简体   繁体   English

Excel VBA-浏览并打开文件,将打开的文件粘贴到宏表中

[英]Excel VBA- Browse and open the files, paste the open files in macro sheet

Am trying to automate, browse the files through search button and open the files and it should be pasted in the next sheet of my macro sheet.我正在尝试自动化,通过搜索按钮浏览文件并打开文件,它应该粘贴到我的宏表的下一张表中。 Pleae help to do in excel vba.请帮助在 excel vba 中做。

I try to open two files and i need to compare the files.我尝试打开两个文件,我需要比较这些文件。

This code will let you browse to a selected file and then open it此代码将让您浏览到选定的文件,然后打开它

Sub OpenFile()
Dim strFileToOpen As Variant

strFileToOpen = Application.GetOpenFilename _
(Title:="Please choose a file to open", _
FileFilter:="Excel Files *.xls* (*.xls*),")

If strFileToOpen = False Then
    MsgBox "No file selected.", vbExclamation, "Sorry!"
    Exit Sub
Else
    Workbooks.Open Filename:=strFileToOpen
End If

End Sub

This will get you started.这会让你开始。 Once it is open, you can write code to copy the sheet(s) into your macro file.打开后,您可以编写代码将工作表复制到您的宏文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM