I am using Excel 2003, SP1.
I have extensive macros in Excel that extracts data from an Oracle
database and creates multiple worksheets to display the data.
On the first sheet, there is a cell that should contain the "machine
number". If the user enters "See Note", the macro is to insert a
textbox that will display the heading: "Machines:" followed by the
list of machine numbers extracted from Oracle. Because I have to
supply the document number and revision in order to retrieve the data
from Oracle, I wrote it as a function. However, in testing, I
changed it to a subroutine and had the same results.
In a blank cell, I have the formula:
=IF(LEFT(O55,3) = "SEE",Get_Ora_Mach(),"")
(I removed the variables being passed for testing purposes)
The function looks like:
Function Get_Ora_Mach()
Dim CreateFlag
Dim BoxTop, BoxWidth, BoxLeft, BoxHeight
Dim BoxName, I
CreateFlag = True
ActiveSheet.Shapes.SelectAll
Debug.Print "Count: " & Selection.ShapeRange.Count
' Look for existing textbox called "VAR_MACH"
For I = 1 To Selection.ShapeRange.Count
If (UCase(Selection.ShapeRange(I).Name) = "VAR_MACH") Then
CreateFlag = False
Exit For
End If
Next I
If (CreateFlag) Then
BoxLeft = 723
BoxWidth = 850 - BoxLeft
BoxTop = 885 - 20 * 4 '(testing: 4 lines in textbox)
BoxHeight = 885 - BoxTop
ActiveSheet.Shapes.AddTextbox
(msoTextOrientationHorizontal, _
BoxLeft, BoxTop, BoxWidth, BoxHeight).Select
BoxName = Selection.Name
ActiveSheet.Shapes(BoxName).Name = "VAR_MACH"
End If
ActiveSheet.Shapes("VAR_MACH").Select
Selection.Characters.Text = "MACHINES:" & Chr(10) & "246014"
& Chr(10) & "246016"
Get_Ora_Mach = ""
End Function
'================================================================
' When run from the Spreadsheet, The textbox is created, but
' the text is not inserted into the box.
' If I create a subroutine to call the function:
'================================================================
Sub add_txtbox()
Dim Result
Result = Get_Ora_Mah()
End Sub
'================================================================
' The function works as expected.
' The same happens if the texbox already exists
'================================================================
I intentionally have not used "forms" because of the volume of
information, as well as .TIF images that must be inserted, cropped,
and rescaled to fit the worksheet.
Any idea why? and how to correct it?