Using Excel VBA to print a PowerPoint file

  • Thread starter Thread starter David Hookham
  • Start date Start date
D

David Hookham

I have an Excel file supported with VBA. One of the requirements of the
code is to open a specified PowerPoint file, print it and then close the
file and exit PowerPoint. Ideally this would be largely invisible to the
user, but that's not essential.

I'm using the code below:

Sub PPTPrint(slink)
Dim PPObj As Object
Set PPObj = CreateObject("PowerPoint.application")
With PPObj
.presentations.Add
.presentations.Open Filename:=slink
.Visible = True
PPObj.ActivePresentation.PrintOptions.PrintInBackground = msoFalse
PPObj.ActivePresentation.PrintOut copies:=1
End With
End Sub

This works fine as long as slink is a qualified filename on a "normal"
filesystem, eg local hard drive or network. However, the files it needs to
open will be stored in a Public Folder within Exchange Server.

If slink is of the form "outlook:\\Public Folders\All Public
Folders\Datafiles\file.ppt" then the code fails. The error reported can
vary, but generally refers to an unfeasibly large line number in the code.

Any thoughts?
 
Steve Rindsberg said:
I've never tried this before, David, and don't run Exchange here so
there's no way to start now. ,-)

My first question, though, would be whether outlook:\\Etcetera is a
protocol known to other apps; that is, can you open files from other
programs by typing in similar ... for want of a better term ... URI
in the File Open dialogs? Can you get a directory of the folder from
a command prompt?

What happens if you start PPT manually, choose File, Open and type in
the full path as given to the file?

There shouldn't be any problems with UNC pathnames.

Ah... good point! I'm beginning to feel pain over this part of what started
as a simple task!
 
I've never tried this before, David, and don't run Exchange here so
Ah... good point! I'm beginning to feel pain over this part of what started
as a simple task!

Can you programmatically get Outlook to [save | detach | write | whatever]
the file to e.g. the user's TEMP folder under a temporary name, then have
PowerPoint open/print that?
 
Steve Rindsberg said:
Ah... good point! I'm beginning to feel pain over this part of what
started as a simple task!

Can you programmatically get Outlook to [save | detach | write |
whatever] the file to e.g. the user's TEMP folder under a temporary
name, then have PowerPoint open/print that?

It's a possibility, but the end result has to run on a system which is
fairly locked down, so the less reliant it is on the local filesystem, the
better. I'll give your suggestion a try though - if it works, bonus ;-p
 
Back
Top