View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Rech Jim Rech is offline
external usenet poster
 
Posts: 2,718
Default Problem with hiden workbooks

Your code ran fine for me with and without commenting out the line. I ran
the code from Word since I don't have VB6 installed but that shouldn't make
any difference. I'm not sure why you want to hide the window though since
Excel itself is not visible so there's nothing to see in any case.

--
Jim
"Daniel Knueven" wrote in message
...
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