Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 21st, 2013, 03:20 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #2 (permalink)  
Old June 21st, 2013, 09:53 PM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
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)
Reply With Quote
  #3 (permalink)  
Old June 22nd, 2013, 05:56 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:24 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.