Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 21st, 2013, 03:20 PM
Registered User
 
Join Date: Jun 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Run time error -2147417851 (80010105) Automation error The server threw an exception

Hi,
I am running the code below in Excel VBA. The main idea of the code is to read some info from excel and create a power point file.

I appreciate your help, thanks

Sub Macro1()
Dim XLApp As Excel.Application
Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim Title(10) As Variant, Connector(10) As String, Chart_Names(10) As Variant, i As Integer



Set PPApp = CreateObject("Powerpoint.Application")
Set PPPres = PPApp.Presentations.Add



For i = 1 To 8

Title(i) = Worksheets("Sheet1").Cells(4 + i, 19)
Chart_Names(i) = Worksheets("Sheet1").Cells(4 + i, 20)
Connector(i) = Worksheets("Sheet1").Cells(4 + i, 21)


Next i



For i = 1 To 8

If (i < 4 Or i = 5) Then

Set PPSlide = PPPres.Slides.Add(i, ppLayoutTitleOnly)
PPSlide.Select

' Reference active slide
Set PPSlide = PPPres.Slides _
(PPApp.ActiveWindow.Selection.SlideRange.SlideInde x)

'Add a Tittle

PPSlide.Shapes.Title.TextFrame.TextRange.Text = Title(i)
Worksheets("Sheet1").ChartObjects(Chart_Names(i)). Select

' Copy chart as a picture
ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, _
Format:=xlPicture

' Paste chart
PPSlide.Shapes.Paste.Select

With PPApp.ActiveWindow.Selection.ShapeRange
.Height = 275 ' resize
.Width = 425 ' resize
.Top = 120 ' reposition
.Left = 140 ' reposition
End With


Set XLApp = GetObject(, "Excel.Application")
XLApp.Range(Connector(i)).Select
XLApp.Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
PPSlide.Shapes.Paste.Select

With PPApp.ActiveWindow.Selection.ShapeRange
' .Height = 275 ' resize
' .Width = 425 ' resize
.Top = 415 ' reposition
.Left = 197 ' reposition
End With

Else

Set PPSlide = PPPres.Slides.Add(i, ppLayoutTitleOnly)
PPSlide.Select

' Reference active slide
Set PPSlide = PPPres.Slides _
(PPApp.ActiveWindow.Selection.SlideRange.SlideInde x)


Set XLApp = GetObject(, "Excel.Application")
XLApp.Range(Chart_Names(i)).Select
XLApp.Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
PPSlide.Shapes.Paste.Select

With PPApp.ActiveWindow.Selection.ShapeRange
.Height = 275 ' resize
.Width = 425 ' resize
.Top = 120 ' reposition
.Left = 140 ' reposition
End With


Set XLApp = GetObject(, "Excel.Application")
XLApp.Range(Connector(i)).Select
XLApp.Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
PPSlide.Shapes.Paste.Select

If i = 6 Then

With PPApp.ActiveWindow.Selection.ShapeRange
.Height = 275 ' resize
.Width = 425 ' resize
.Top = 315 ' reposition
.Left = 146 ' reposition
End With

Else
If i = 7 Or i = 8 Then
With PPApp.ActiveWindow.Selection.ShapeRange
.Height = 1 ' resize
.Width = 1 ' resize
.Top = 1 ' reposition
.Left = 1 ' reposition
End With
End If
End If

End If


Next



With PPPres
.SaveAs "C:\Users\DG93796\Documents\MyPreso.ppt"
.Close
End With

PPApp.Quit

Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

'End If



End Sub
 
Old June 21st, 2013, 09:53 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Can you please specify where the error occurs (line of code)

The chances are the code is trying to reference the object (either Powerpoint or Excel) but the application/object is not available

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)
 
Old June 22nd, 2013, 05:56 AM
Registered User
 
Join Date: Jun 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank Shasur. The problems is that the error is inconsistent and doesnt give the the typical yellow line, it just breaks while running.

The strange thing is that it doesn't brake all the time, out 10 trials 2 run fine.
I was reading a lot trying to find possible causes and found:

1. Go to Macro security and "Trust vbA"
2. Turn calculation to manual.


This seems to help immediately the run after but then when I tried to run it
again it gives me the same error.

Thanks a lot- I've never got such an inconsistent error before.

David





Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Run-time error '20599'; Cannot open SQL Server manishashar888 Pro VB Databases 7 March 20th, 2007 07:04 AM
run-time error '20599' : cannot find sql server juicyfruit SQL Server 2000 1 February 16th, 2006 06:25 AM
Run Time Error JBond Access VBA 0 May 27th, 2004 09:50 AM
RUN-TIME ERROR compcad Beginning VB 6 2 May 21st, 2004 02:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.