P
Project Mangler
My understanding of fully qualified ranges is a little flimsy. Perhaps this
is why the copy operation in the last line of this code fails with an
"Object doesn't support this property or method".
I would be grateful if someone could point out where I'm going wrong? Is it
the variable typing, the qualification of the ranges or am I just using the
wrong syntax?
Thanks!
Sub procOpenBook()
Dim Book1 As Workbook 'target book
Dim i As Long ' loop variable
Dim wbName As Variant 'file to be opened
Dim shtlastcell As Long 'cell on target sheet at which rows will be
inserted
Dim selRows As Long 'number of elected rows on source sheet
Dim srcSheetName As String ' name of last
Dim srcSheetRng As Range 'selected range on source sheet
Dim srcBook As Workbook ' source workbook
Set srcBook = ActiveWorkbook
Set srcSheetRng = ActiveWindow.RangeSelection
srcSheetName = ActiveSheet.Name
selRows = Selection.Rows.Count
wbName = Application.GetOpenFilename _
(FileFilter:="microsoft excel files (*.xls), *.xls", _
Title:="Get File", MultiSelect:=False)
If wbName <> False Then
Set Book1 = Workbooks.Open(wbName)
Else
Exit Sub
End If
Book1.Sheets(1).Activate
shtlastcell = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To selRows
Rows(shtlastcell + i).Insert (xlShiftDown)
Next
srcBook.srcSheetName.Range(srcSheetRng).Copy
Destination:=Book1.Sheets(1).Range("A" & shtlastcell + 1)
End Sub
is why the copy operation in the last line of this code fails with an
"Object doesn't support this property or method".
I would be grateful if someone could point out where I'm going wrong? Is it
the variable typing, the qualification of the ranges or am I just using the
wrong syntax?
Thanks!
Sub procOpenBook()
Dim Book1 As Workbook 'target book
Dim i As Long ' loop variable
Dim wbName As Variant 'file to be opened
Dim shtlastcell As Long 'cell on target sheet at which rows will be
inserted
Dim selRows As Long 'number of elected rows on source sheet
Dim srcSheetName As String ' name of last
Dim srcSheetRng As Range 'selected range on source sheet
Dim srcBook As Workbook ' source workbook
Set srcBook = ActiveWorkbook
Set srcSheetRng = ActiveWindow.RangeSelection
srcSheetName = ActiveSheet.Name
selRows = Selection.Rows.Count
wbName = Application.GetOpenFilename _
(FileFilter:="microsoft excel files (*.xls), *.xls", _
Title:="Get File", MultiSelect:=False)
If wbName <> False Then
Set Book1 = Workbooks.Open(wbName)
Else
Exit Sub
End If
Book1.Sheets(1).Activate
shtlastcell = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To selRows
Rows(shtlastcell + i).Insert (xlShiftDown)
Next
srcBook.srcSheetName.Range(srcSheetRng).Copy
Destination:=Book1.Sheets(1).Range("A" & shtlastcell + 1)
End Sub