Link to home
Start Free TrialLog in
Avatar of drtopserv
drtopservFlag for Israel

asked on

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:}
Avatar of ste5an
ste5an
Flag of Germany image

Well, looks like homework. Guess what you xlSheet variable is for..
Avatar of drtopserv

ASKER

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 .
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.
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfecto Norie,... work like a charm!:|}