I have a form with 2 buttons. This program is suppose to call setup and readdata routine from module1 when I click cmd1 inside from1. My problem started with the statement
"For each c in selection" I get the error message <oject required> for this statement.

I thought i have already dim c as excel.range inside the module 1. Can somebody please help.


private sub cmd1_click()
end sub

private sub cmd2_click()
set appxls = nothing
set wkbook = nothing
end sub

' Module 1
Option Explicit
Public appXls As Excel.Application
Public wkBook As Excel.Workbook

Sub setUp()
Dim mfile$

On Error Resume Next

Set appXls = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set appXls = CreateObject("Excel.Application")
End If

On Error GoTo 0

mfile = "c:\test\ABCD.xls"
Set wkBook = appXls.Workbooks.Open(mfile)
End Sub

Sub cleanUp()
Set appXls = Nothing
Set wkBook = Nothing
End Sub

Sub ReadData(myRange As String)
Dim c As Excel.Range

With appXls.ActiveSheet
For Each c In Selection
next c
end with
end sub