MS Office Forum / General PowerPoint Questions / May 2006
0x800A01A8 Exception on setting fill color from VB2005
|
|
Thread rating:  |
Dan Brusco - 02 Mar 2006 21:38 GMT I have a program I am upgrading from VB6 to VB2005. This function works from VB6, but generates an exception in VB2005. I am setting a table cell shape fill forecolor to RBG (200,200,200) [grey]. The code which fails is basically as follows:
With pptPresentation.Slides.Item(pintSlide).Shapes.Item(intTableID).Table ... .Cell(j, i).Shape.Fill.ForeColor.RGB = RGB(200, 200, 200)
I have tried every variation I can think of. Any help would be greatly appreciated.
Steve Rindsberg - 02 Mar 2006 23:02 GMT > I have a program I am upgrading from VB6 to VB2005. This function works from > VB6, but generates an exception in VB2005. I am setting a table cell shape [quoted text clipped - 7 lines] > I have tried every variation I can think of. Any help would be greatly > appreciated. Do you get some kind of error message?
A couple of ideas:
pintSlide and intTableID -- PPT is looking for Longs in both cases. ISTR that .Net ints are equivalent to VBA longs, but it's worth checking.
Does .Net have an RGB method?
----------------------------------------- Steve Rindsberg, PPT MVP PPT FAQ: www.pptfaq.com PPTools: www.pptools.com ================================================
Dan Brusco - 02 Mar 2006 23:17 GMT The full exception message is:
Run-time exception thrown : System.Runtime.InteropServices.COMException - Exception from HRESULT: 0x800A01A8
Not much help.
Dan
> > I have a program I am upgrading from VB6 to VB2005. This function works from > > VB6, but generates an exception in VB2005. I am setting a table cell shape [quoted text clipped - 22 lines] > PPTools: www.pptools.com > ================================================ Dan Brusco - 02 Mar 2006 23:46 GMT Sorry I didn't answer everything all at once...
I tried defining the variables as longs... This caused an abort. I changed them back to integer (they originally were defined as short) and still am getting the error.
Yes, .net has an RGB function. The error almost makes me believe that there's some kind of problem in the "interop" interface from .Net to the PowerPoint .Shape.Fill.Forecolor.RGB property.
Unfortunately, I can make this even more obscure. I had forgotten this, but earlier in the same routine, I have a .cell (j,i).shape.fill.forecolor.rgb = rgb (255, 255, 255) and it works. All that I want to do is set the background on specific cells to a light grey. If you have any other suggestions, I'm open to trying something different.
Dan
> > I have a program I am upgrading from VB6 to VB2005. This function works from > > VB6, but generates an exception in VB2005. I am setting a table cell shape [quoted text clipped - 22 lines] > PPTools: www.pptools.com > ================================================ Steve Rindsberg - 03 Mar 2006 02:35 GMT > Sorry I didn't answer everything all at once... > [quoted text clipped - 11 lines] > background on specific cells to a light grey. If you have any other > suggestions, I'm open to trying something different. Weird!
Can you post a bit more code surrounding the bit where the error occurs? I don't speak .Net but maybe someone else can step in ...
> Dan > [quoted text clipped - 24 lines] > > PPTools: www.pptools.com > > ================================================ ----------------------------------------- Steve Rindsberg, PPT MVP PPT FAQ: www.pptfaq.com PPTools: www.pptools.com ================================================
Dan Brusco - 03 Mar 2006 15:23 GMT This function copies cells from an Excel spreadsheet to a PowerPoint presentation slide. During the copy, it tests to see if the values are above, between, or below set thresholds. For above, it sets the font format bold, italic. For below (where the error occurs), it sets the fill color to a grey.
What's really weird is that this works fine when run from VB6. There must be something odd about the way .Net interfaces with the PPT OLE object.
Here is the code: Dim i As Integer Dim j As Integer Dim intCellValue As Short Dim intTableID As Integer Dim intColStart As Short Dim intColEnd As Short Dim intRowStart As Short Dim intRowEnd As Short Dim intColor As Integer
Dim lngAnswer As Integer
Dim blnValidCellValue As Boolean Dim blnAutoReplace As Boolean
intTableID = -1 For i = 1 To pptPresentation.Slides.Item(pintSlide).Shapes.Count If pptPresentation.Slides.Item(pintSlide).Shapes.Item(i).HasTable Then intTableID = i Exit For End If Next i If intTableID < 0 Then Exit Function With pptPresentation.Slides.Item(pintSlide).Shapes.Item(intTableID).Table intColStart = (Asc(pstrFromCell) - Asc("A")) intColEnd = ((Asc(pstrToCell) - Asc(pstrFromCell)) + 1) intRowStart = Int(CDbl(Mid(pstrFromCell, 2))) intRowEnd = Int(CDbl(Mid(pstrToCell, 2))) If intColStart + intColEnd > .Columns.Count Then MsgBox("The range specified to paste cells into the table has more columns than the PowerPoint table. Please adjust the size of the PowerPoint table.") Exit Function End If For j = intRowStart To intRowEnd For i = 2 To pptPresentation.Slides.Item(pintSlide).Shapes.Item(intTableID).Table.Columns.Count .Cell(j, i).Shape.TextFrame.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoFalse .Cell(j, i).Shape.TextFrame.TextRange.Font.Underline = Microsoft.Office.Core.MsoTriState.msoFalse .Cell(j, i).Shape.Fill.ForeColor.RGB = RGB(255, 255, 255) '.Cell(j, i).Shape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoFalse .Cell(j, i).Shape.TextFrame.TextRange.Text = "" Next i Next j System.Windows.Forms.Application.DoEvents() blnAutoReplace = False For j = intRowStart To intRowEnd For i = intColStart + 1 To ((Asc(pstrToCell) - Asc(pstrFromCell)) + 1) + intColStart blnValidCellValue = True If ExcelApp.WorksheetFunction.IsErr(ExcelWorksheet.Cells.Item(j, i)) Then If blnAutoReplace Then intCellValue = 0 Else lngAnswer = MsgBox("The Excel spreadsheet contains an error result in cell " & Chr(i + Asc("A") - 1) & j & ". Click Yes to substitute a zero or No to stop processing this slide.", MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2 + MsgBoxStyle.Question) If lngAnswer = MsgBoxResult.Yes Then blnAutoReplace = True intCellValue = 0 Else Exit Function End If End If Else If IsNumeric(ExcelWorksheet.Cells.Item(j, i).Value) And Len(CStr(ExcelWorksheet.Cells.Item(j, i).Value)) <> 0 Then intCellValue = System.Math.Round(ExcelWorksheet.Cells.Item(j, i).Value) Else blnValidCellValue = False End If End If If blnValidCellValue Then .Cell(j, i).Shape.TextFrame.TextRange.Text = Format(intCellValue, "#0") If pintSampleRow < 0 Or (j - intRowStart + 1 <> pintSampleRow) Then If ((intCellValue >= pintMaxVaule) And (pintMaxVaule >= 0)) Then .Cell(j, i).Shape.TextFrame.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoTrue .Cell(j, i).Shape.TextFrame.TextRange.Font.Underline = Microsoft.Office.Core.MsoTriState.msoTrue .Cell(j, i).Shape.TextFrame.TextRange.Font.Italic = Microsoft.Office.Core.MsoTriState.msoFalse '.Cell(j, i).Shape.Fill.Visible() = Microsoft.Office.Core.MsoTriState.msoFalse ElseIf ((intCellValue <= pintMinValue) And (pintMinValue >= 0)) Then
.Cell(j, i).Shape.TextFrame.TextRange.Font.Italic = Microsoft.Office.Core.MsoTriState.msoTrue intColor = RGB(192, 192, 192) .Cell(j, i).Shape.Fill.ForeColor.RGB = intColor .Cell(j, i).Shape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue .Cell(j, i).Shape.Fill.Solid() .Cell(j, i).Shape.TextFrame.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoFalse .Cell(j, i).Shape.TextFrame.TextRange.Font.Underline = Microsoft.Office.Core.MsoTriState.msoFalse Else .Cell(j, i).Shape.TextFrame.TextRange.Font.Italic = Microsoft.Office.Core.MsoTriState.msoFalse '.Cell(j, i).Shape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoFalse .Cell(j, i).Shape.TextFrame.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoFalse .Cell(j, i).Shape.TextFrame.TextRange.Font.Underline = Microsoft.Office.Core.MsoTriState.msoFalse End If ElseIf (j - intRowStart + 1 = pintSampleRow) Then .Cell(j, i).Shape.TextFrame.TextRange.Text = "[" & ExcelWorksheet.Cells.Item(j, i).Value & "]" .Cell(j, i).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = PowerPoint.PpParagraphAlignment.ppAlignCenter .Cell(j, i).Shape.TextFrame.TextRange.Font.Italic = Microsoft.Office.Core.MsoTriState.msoTrue .Cell(j, i).Shape.TextFrame.TextRange.Font.Size = 10 .Cell(j, i).Shape.TextFrame.TextRange.Font.Name = "Arial" End If Else .Cell(j, i).Shape.TextFrame.TextRange.Text = ExcelWorksheet.Cells.Item(j, i).Value End If Next i System.Windows.Forms.Application.DoEvents() Next j End With ExcelApp.Quit() ExcelWorksheet = Nothing ExcelApp = Nothing
> > Sorry I didn't answer everything all at once... > > [quoted text clipped - 51 lines] > PPTools: www.pptools.com > ================================================ aweiss@teamtechsystems.com - 03 Mar 2006 21:56 GMT I haven't solved this problem completly yet, but I think I've gotten further but calling the Solid() method on the fill class before using it:
fill.Solid(); fill.BackColor.RGB = Util.RGB2BGR(style.BgndColor);
good luck, I'll post more if I ever get this working reliably -andy
Dan Brusco - 03 Mar 2006 22:49 GMT Well, I have a solution that I don't particularly trust. It is working at the moment, however.
I eliminated the loop at the beginning of the function which sets the fill and font to a "cleared" state. If I only attempt to access this once within the function for each cell for some reason it appears to work. This really looks like a bug somewhere in the interop interface, but at least I have a temporary workaround.
Thanks for the help on this.
> I haven't solved this problem completly yet, but I think I've gotten > further but calling the Solid() method on the fill class before using [quoted text clipped - 5 lines] > good luck, I'll post more if I ever get this working reliably > -andy Steve Rindsberg - 04 Mar 2006 01:47 GMT > Well, I have a solution that I don't particularly trust. It is working at > the moment, however. [quoted text clipped - 6 lines] > > Thanks for the help on this. Sometimes a sounding board is all it takes. Any time you want to hum a few bars, c'mon back and we'll vibrate sympathetically. ;-)
Glad you got it sorted!
> > I haven't solved this problem completly yet, but I think I've gotten > > further but calling the Solid() method on the fill class before using [quoted text clipped - 5 lines] > > good luck, I'll post more if I ever get this working reliably > > -andy ----------------------------------------- Steve Rindsberg, PPT MVP PPT FAQ: www.pptfaq.com PPTools: www.pptools.com ================================================
Yury Gavris - 07 May 2006 22:55 GMT I've faced the similar problem. There is a sample code, that throws the same exception:
Slide slide = app.ActivePresentation.Slides[1]; PowerPoint.ShapeRange range = slide.Shapes[1].Ungroup(); // Two simple shapes! range[1].Fill.ForeColor.RGB = 0xFF00; // It's OK. Left shape colored to green! range.Group();
//------------------- // doing something //------------------- range = slide.Shapes[1].Ungroup(); range[2].Fill.ForeColor.RGB = 0xFF; // It's OK. Right shape colored to red! range[1].Fill.ForeColor.RGB = 0xFF; // COMException - Exception from HRESULT: 0x800A01A8.
How did you solve your problem, maybe you've found good solution? I need help.
> > Well, I have a solution that I don't particularly trust. It is working at > > the moment, however. [quoted text clipped - 27 lines] > PPTools: www.pptools.com > ================================================ Steve Rindsberg - 08 May 2006 01:05 GMT > I've faced the similar problem. There is a sample code, that throws the same > exception: > > Slide slide = app.ActivePresentation.Slides[1]; > PowerPoint.ShapeRange range = slide.Shapes[1].Ungroup(); > // Two simple shapes! And the original group shape no longer exists.
> > range[1].Fill.ForeColor.RGB = 0xFF00; > // It's OK. Left shape colored to green! > > range.Group(); And now you've created a new shape, the group consisting of the original two shapes.
> //------------------- > // doing something > //------------------- > > range = slide.Shapes[1].Ungroup(); Shapes[1] doesnt' refer to the same shape it referred to before. That shape no longer exists since you ungrouped it.
I'm not sure if that entirely explains the problem but it's worth looking into.
> range[2].Fill.ForeColor.RGB = 0xFF; > // It's OK. Right shape colored to red! > > range[1].Fill.ForeColor.RGB = 0xFF; > // COMException - Exception from HRESULT: 0x800A01A8.
> How did you solve your problem, maybe you've found good solution? I need > help. [quoted text clipped - 30 lines] > > PPTools: www.pptools.com > > ================================================ ----------------------------------------- Steve Rindsberg, PPT MVP PPT FAQ: www.pptfaq.com PPTools: www.pptools.com ================================================
|
|
|