View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Daniel Knueven Daniel Knueven is offline
external usenet poster
 
Posts: 2
Default Problem with hiden workbooks

I am using a hidden workbook to generate graphs using Excel. I was having a
problem adding a label to the chart while the workbook was hidden. So, I
installed SP1 for Office 2003 to see if that would fix the problem. Now, I
can't even add a chart to the workbook when it is hidden. I am running on
Windows XP SP2. I would appreciate any help.

Included is code that can reproduce the problem:

'-----------------------------------------------------------------------
Option Explicit

Private Const msoOrientationHorizontal As Long = 1
Private Const msoTrue As Long = -1

Private Sub Form_Load()

Dim oExcelApp As Object
Dim oExcelBook As Object
Dim oExcelChart As Object
Dim oExcelShape As Object

Set oExcelApp = CreateObject("Excel.Application")

Set oExcelBook = oExcelApp.Workbooks.Add

' Comment out the following line and everything will work
oExcelBook.Windows(1).Visible = False

' If SP1 for office 2003 is installed, this line fails with the
following error
' Run-time error '-2147417851 (80010105)': Method 'Add' of object
'Sheets' failed
Set oExcelChart = oExcelBook.Charts.Add

' If SP1 is not installed, this line fails with the following error
' "run-time error '1004': Application-defined or object-defined error"
Set oExcelShape = oExcelChart.Shapes.AddLabel(msoOrientationHorizont al,
0, 0, 10, 10)

oExcelShape.TextFrame.Characters.Text = "Hello"
oExcelShape.Line.Visible = msoTrue
oExcelShape.TextFrame.AutoSize = True

oExcelBook.Close False

oExcelApp.Quit

Set oExcelShape = Nothing
Set oExcelChart = Nothing
Set oExcelBook = Nothing
Set oExcelApp = Nothing

Unload Me

End Sub