Unable to Set Presentation Object

Erick

Active Member
Joined
Feb 26, 2003
Messages
362
I am trying to create a word report & a powerpoint presentation at the same time using access. I have simplified my vb access code below so that it is just contains the part where I am having difficulty.

The code below will open a 'Doc1.doc' and 'Presentation1.ppt'. You will have to create these files and change the 'FilePath' variable if you want to trial it.

The problem that I have with it is, once it reaches the 'Stop' line, I am able to set the variable 'objWordDoc' to 'Doc1.doc', which was the active document, but I cannot set the variable 'objPresentation' to 'Presentation1.ppt' which is the active presentation (i.e. @ Stop, objWordDoc = "Doc1.doc", whilst objPresentation = ""). As far as I can tell, the powerpoint section of the code is identical to the word part of the code.

Sub OpenWord_PPoint()
Dim objWord As Object
Dim objWordDoc As Object
Dim objPPoint As Object
Dim objPresentation As Object
'Dim objPPoint As PowerPoint.Application
'Dim objPresentation As PowerPoint.Presentation
Dim FilePath As String
Dim DocumentName As Variant
Dim PresentationName As Variant
FilePath = "D:\Documents and Settings\DZU\My Documents"
'Start Microsoft Word
Set objWord = CreateObject("Word.Application")
DocumentName = "Doc1.doc"
With objWord
.Visible = True
.Documents.Open FilePath & "\" & DocumentName
Set objWordDoc = .activedocument
End With

'Start Powerpoint Presentation
Set objPPoint = CreateObject("PowerPoint.Application")
PresentationName = "Presentation1.ppt"
With objPPoint
.Visible = True
.Presentations.Open FilePath & "\" & PresentationName
Set objPresentation = .ActivePresentation
End With
Stop
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi,

Your code worked fine for me as it is. Once the code stops if you click View, Locals Window does the objPresentation variable have a value of Nothing? Seems odd if that is the case as the code should generate a run-time error.

DK
 
Upvote 0
Thanks for looking into this for me DK.

when i go to local window, it says that objPresentation is "Presentation1.ppt", so i guess it works???:???:

Why is it that when i watch objWordDoc, it returns a "Doc1.doc" but objPresentation is just blank???:confused:
 
Upvote 0
Which column is blank when you use the Watch Window? When I run it and look at those two variables in the watch window I get a value of "Microsoft Word" for objWord and blank for objPresentation. Not sure why that is....and not sure if it really matters (unless you're using it for some purpose?). I usually use the locals window as it allows you to also "watch" variables without having to actually add the watches in the first place.

HTH
DK
 
Upvote 0
when watch for objWordDoc, the value column comes back as "Doc1.doc". But when I watch objPresentation, the value column is blank. I am expecting it come back with "Presentation1.ppt"

This code will do some copying & pasting of charts, tables and values from Access to both the word doc & powerpoint presentation. I was going to use these variables to switch between the two applications to paste and save at the end.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top