Below is a bit more of the code. I set the variable "insheet" as a sheet, I then pass it as a parameter to the subroutine. In the subroutine, the range is also set at a sheet.
Sub inputonly()
Dim insheet As Worksheet
destfilename = ActiveWorkbook.Name
Range("a2").Select
destrange = ActiveCell.Address
Call getname(infile)
If infile = False Then
Exit Sub
Else
insheet = Left(infile, Len(infile) - 4)
Call input_wks(destfilename, "lgd1000", destrange, infile, insheet, "a2")
End If
Sub input_wks(destbook, destsheet, destrange, sourcefile, sourcesheet, sourcerange)
Dim wb1 As Workbook, wb2 As Workbook, ws1 As Worksheet
Dim ws2 As Worksheet, rng1 As Range, rng2 As Range
Set wb1 = Workbooks(destbook)
Set ws1 = wb1.Worksheets(destsheet)
Set rng1 = ws1.Range(destrange)
rng1.Value = " "
Workbooks.Open FileName:=sourcefile
Set wb2 = ActiveWorkbook
Set ws2 = wb2.Worksheets(sourcesheet)
Set rng2 = ws2.Range(sourcerange)
Set rng2 = ws2.UsedRange
Set rng1 = rng1.Resize(rng2.Rows.Count, rng2.Columns.Count)
rng1.Value = rng2.Value
wb2.Close False
End Sub
1) When I EXCLUDE the Dim statement (bolded above in the calling program) the macro fails in the subroutine in the "set ws2" statement (bolded). The macro goes so far as to read in the input file (named "infile"), but doesn't go through the copy routine
2)When I INCLUDE the DIM statement the macro gives the error message
"Object variable or with block variable not set". It never even gets to read in the input file.
Thanks,