我不是VBA的最佳人选,而且多年来没有触及它,因此我求助于教程,所以我希望有人可以提供帮助!
从长远来看,我按以下顺序尝试:
到目前为止,我已经进行了搜索/切割和更改,并发现了以下内容(感谢JMax在此网站上)
Sub test()
Dim wb As Workbook, wb2 As Workbook
Dim ws As Worksheet
Dim vFile As Variant
'Set source workbook
Set wb = ActiveWorkbook
'Open the target workbook
vFile = Application.GetOpenFilename("Excel-files,*.xls", _
1, "Select One File To Open", , False)
'if the user didn't select a file, exit sub
If TypeName(vFile) = "Boolean" Then Exit Sub
Workbooks.Open vFile
'Set targetworkbook
Set wb2 = ActiveWorkbook
'For instance, copy data from a range in the first workbook to another range in the other workbook
wb2.Worksheets("Sheet1").Range("C3:D4").Value = wb.Worksheets("Sheet3").Range("A1:B2").Value
End Sub
对我来说这看起来顺序然而当它打开excel文档时,它会返回'下标超出范围'消息。
我错过了什么?细胞和命名似乎对我来说是正确的:(。
谢谢,
戴夫