View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
kounoike[_2_] kounoike[_2_] is offline
external usenet poster
 
Posts: 126
Default Cell formatting not applied

I'm using Excel 2003 SP2.
I tested your code and it worked for me. the tested codes are below and run
boldtest.
Are you sure you are on worksheets(1)?

Microsoft Excel Objects / Sheet1:
Public Sub BoldItem(row, col As Integer)
With Worksheets(1)
.Cells(row, col).Font.bold = True
End With
End Sub

Modules / Module1:
Private Function ItemNo(row, col As Integer) As String
Dim n As Integer
With Worksheets(1)
Call .BoldItem(row, 1)
End With
ItemNo = "unknown"
End Function

Sub boldtest()
Call ItemNo(ActiveCell.row, 1)
End Sub

keizi

wrote in message
oups.com...
I have a weird cell formatting problem in Excel 2002 SP3 and Excel
2003 SP1. If I call my formatting procedure from code on Sheet1
directly, the formatting is applied. However, if I call the same
procedure from a function in Module1 the formatting procedure
executes, but the formatting is not applied. A Google search turned up
the following, but this is not really helpful as the poor guy gave up
without finding a solution.

http://forums.techguy.org/developmen...ormat-not.html

Snippets from my code are as follows:

Microsoft Excel Objects / Sheet1:
Public Sub BoldItem(row, col As Integer)
With Worksheets(1)
.Cells(row, col).Font.Bold = True
End With
End Sub

Private Sub CommandButton1_Click()
Call BoldItem(15, 1)
End Sub

I click CommandButton1 and the text in cell A15 appears bold. Hooray
it works.

Modules / Module1:
Private Function ItemNo(row, col As Integer) As String
Dim n As Integer
With Worksheets(1)
...
Call .BoldItem(row, 1)
...
End With
End Function

The procedure BoldItem executes when called, but no bold effect is
visible on my text. I'm confused.

I tried to trick Excel into thinking that the call to BoldItem was
coming from code on Sheet1:
Modules / Module1:
Private Function ItemNo(row, col As Integer) As String
Dim n As Integer
With Worksheets(1)
...
Call .CommandButton1_Click
...
End With
End Function

Alas BoldItem executes, but has no effect. Any ideas are most welcome.

Craig.