loop through cells in excel file from access vba

Hi all,

I have this code in Access, that open excel file and format it:

Dim xlApp As Object
Dim xlSheet As Object

Set xlApp = CreateObject("Excel.Application")
Set xlSheet = xlApp.Workbooks.Open(sFile).Sheets(1)

With xlApp

.Application.Range("A2:A10000").Select

Dim cell As Range

For Each cell In xlApp

If cell.Value="Hi" Then
   .Application.cell.Interior.ColorIndex = 3

End If

Next

End with


How can i fix this code to work in access .
the problem is on looping through cells and checking the value of the cell :



Dim cell As Range

For Each cell In xlApp

If cell.Value="Hi" Then
   .Application.cell.Interior.ColorIndex = 3

End If

Next


thanks in regard:}
drtopservAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Well, looks like homework. Guess what you xlSheet variable is for..
0
drtopservAuthor Commented:
I just paste portion from whole code, that just open excel file then start process of formatting it in the background then save it then exit .

everything works perfect, but when it comes to format a cell depend of the value of it . then i stuck there.
Set xlSheet = xlApp.Workbooks.Open(sFile).Sheets(1)
opens the file mention in previous code .
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Doesn't look like homework to me ...

Does your code NOT check the value of the "cell" variable in this line:

If cell.Value="Hi" Then

If not, put a breakpoint in the code and run the procedure. When it stops, enter this in the Immediate window:

?cell.Value

And press the Enter key, then post the results back here.
0
NorieVBA ExpertCommented:
Perhaps.
Dim xlApp As Object
Dim xlBook As Object 
Dim xlSheet As Object
Dim xlRange As Object
Dim cell As Object

Set xlApp = CreateObject("Excel.Application")
Set xlBook= xlApp.Workbooks.Open(sFile)
Set xlSheet = xlBook.Sheets(1)

With xlSheet

    Set xlRange  =.Range("A2:A10000")

    For Each cell In xlRange

        If cell.Value="Hi" Then
            cell.Interior.ColorIndex = 3

        End If

    Next cell 

End With

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
drtopservAuthor Commented:
Perfecto Norie,... work like a charm!:|}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.