By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,534 Members | 2,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,534 IT Pros & Developers. It's quick & easy.

problem with vb.net and powerpoint automation

P: n/a
Rut
Does anyone know how to start powerpoint from vb.net without the ppt
screen appearing. I want to keep it hidden? Using this code:

Try
pp = New PowerPoint.Application
pp.Visible = Office.MsoTriState.msoTrue
pp.WindowState =
PowerPoint.PpWindowState.ppWindowMinimized

Application.DoEvents()
Catch ex As Exception
MsgBox("Error opening powerpoint. Error is: " &
ex.ToString)
Me.Close()
Exit Sub
End Try

The main ppt screen appears momentarily and then minimizes. I've tried
setting .visible to false and get error message: Invalid operation.
Hiding application is not allowed.

Is there some way to lock the screen to prevent this initial
flickering?

Thanks,
RUt
Post a follow-up
Nov 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On 26 Apr 2004 07:39, ru*****@rjrt.com (Rut) wrote:
Does anyone know how to start powerpoint from vb.net without the ppt
screen appearing. I want to keep it hidden? Using this code: Is there some way to lock the screen to prevent this initial
flickering?

What if you pass the /S command-line switch to PowerPoint when you start
it? That's supposed to suppress the splash screen.

--
-Ben-
Ben M. Schorr, MVP-OneNote
OneNote FAQ: http://home.hawaii.rr.com/schorr/Com...OneNoteFAQ.htm
SchorrTech Blog: http://www.thespoke.net/MyBlog/bschorr/MyBlog.aspx
Nov 20 '05 #2

P: n/a


Since I'm using the object model, there is no way to pass command line
parameters (that I'm aware of).

Thanks,
rut

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3

P: n/a
Just curious... What happens if you leave out the "Visible" and
"WindowState" properties? I haven't worked with PowerPoint, but I have
automated Excel from VB.NET and never had to change any of these settings to
keep the application from appearing.

Scott
"Mike Rutledge Rutledge" <ru*****@rjrt.com> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...


Since I'm using the object model, there is no way to pass command line
parameters (that I'm aware of).

Thanks,
rut

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #4

P: n/a


I get an error msg saying powerpoint frame window does not exist.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #5

P: n/a
What functions are you trying to perform using PowerPoint automation
(loading a file, saving a file, creating a presentation, etc.)? It sounds as
though you are trying to do things that require the window to be shown while
you have the window hidden or minimized. If you could show some more code it
would help.

Scott
"Mike Rutledge Rutledge" <ru*****@rjrt.com> wrote in message
news:e4*************@tk2msftngp13.phx.gbl...


I get an error msg saying powerpoint frame window does not exist.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #6

P: n/a


Basically, I'm opening a number of different presentations, pulling
individual slides from these presentations into a new presentation, and
finally showing the new presentation in slidesorter view. Here is all
the code:
Sub BuildPresentation()
'Dim pp As PowerPoint.Application
Dim pp As Object
Dim pres1 As PowerPoint.Presentation
Dim pres2 As PowerPoint.Presentation
Dim ppSlides As PowerPoint.Slides
Dim ppSlide As PowerPoint.Slide
Dim newSlide As PowerPoint.Slide
Dim cnt As Integer
Dim i, index, j As Integer
Dim tmp As String
Dim slide As String
Dim num1, num2
Dim oldGatefold, newGatefold As String
Try
'Create a powerpoint object
pp = CreateObject("PowerPoint.Application")
'pp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized
pp.Visible = Office.MsoTriState.msoTrue
pp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized

Application.DoEvents()
Catch ex As Exception
MsgBox("Error opening powerpoint. Error is: " & ex.ToString)
Me.Close()
Exit Sub
End Try

Try

'We have to open this template file so the slides we pull
out
'will have the correct templated scheme
pres2 =
pp.Presentations.Open("C:\DATA\Powerpnt\caps\_tmp. pot")

Catch ex As Exception
MsgBox("Error opening Powerpoint template. Error is: " &
ex.ToString)
Me.Close()
Exit Sub
End Try

'Keep form on top
Me.TopMost = True
Application.DoEvents()

pb1.Maximum = progCnt
lblProgress.Text = "Building Presentation. Please wait..."

' MsgBox("Starting build")

Try
'Slides can be in a number of different gatefolds (different
ppt presentations.
'We cycle through and pull out the slides for each gatefold
and add them
'to a new presentation.
For i = 1 To UBound(arrGateFolds)
tmp = arrGateFolds(i)
pb1.Value = i 'increment progress bar
' MsgBox("tmp: " & tmp)
Application.DoEvents()
If RTrim(tmp) = "" Then Exit For
'The entry will have a gatefold name, space, slide
number
'We need to separate them out
index = InStr(tmp, " ")
newGatefold = Mid(tmp, 1, index - 1)
'MsgBox("Gatefold: " & newGatefold)
slide = RTrim(Mid(tmp, index + 1, 20))
'MsgBox("slide: " & slide)

'If the gatefold name changes we need to close that
'presentation and open the new one.
If newGatefold <> oldGatefold Then
If Not IsNothing(pres1) Then pres1.Close()
pres1 = pp.Presentations.Open(newGatefold)
oldGatefold = newGatefold
End If

'try to pull out the desired slide
Try
ppSlide = pres1.Slides.Item(CInt(slide))
Catch ex As Exception
'must not exist so set slide to nothing
MsgBox("Error opening slide: " & newGatefold & " " &
slide)
ppSlide = Nothing
End Try

'copy and paste the slide to new presentation
If Not IsNothing(ppSlide) Then
pres1.Slides.Item(CInt(slide)).Copy()
pres2.Slides.Paste()
End If
Next

Catch ex As Exception
MsgBox("Error adding slides to new presentation. Error is: "
& ex.ToString)
pres1.Close()
pres2.Close()
pp.Quit()
Me.Close()
Exit Sub
End Try

'Let's delete the first slide as it is the template slide
pres2.Slides.Item(1).Delete()
pres2.SaveAs(ppFileName,
PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Office.MsoTriState.msoTrue)
pp.Windows.Item(2).ViewType =
PowerPoint.PpViewType.ppViewSlideSorter
pres1.Close()
pres2.Save()
pres2.Saved = Office.MsoTriState.msoTrue

'Display that we have saved new presentation
lblProgress.Text = "Presentation saved as: " & ppFileName
Application.DoEvents()
t2.Enabled = True
While t2.Enabled = True
Application.DoEvents()
If t2.Enabled = False Then Exit While
'Just loop here a few seconds to show message.
End While

pp.WindowState = PowerPoint.PpWindowState.ppWindowMaximized
pp.Presentations.Item(1).Saved = Office.MsoTriState.msoTrue
End Sub

presentation names and a slide number is passed into the array.
Something like C:\ppt\sales.ppt 4 means pull the 4th slide out of
this presentation and paste it into the new one.

Thanks for taking the time to look at this.

Rut

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #7

P: n/a
I'm afraid you may be out of luck. It seems that you must set the "Visible"
property to True to be able to open a presentation. Therefore, the window
will always be shown even if it's only for a brief moment. My only other
thought was to set the location of the window so that it was off screen when
it was first shown. However, this can't be done if the window is maximized
or minimized which depends on the last state the window was in. It seems
Microsoft never thought of this scenario. The only examples I've seen all
have a call to set "Visible = True" which shows the form. What's the point
in automation if the window has to be visible? I'd be interested to see the
solution if you find one.

Sorry I couldn't be of more help...

Scott
"Mike Rutledge Rutledge" <ru*****@rjrt.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...


Basically, I'm opening a number of different presentations, pulling
individual slides from these presentations into a new presentation, and
finally showing the new presentation in slidesorter view. Here is all
the code:
Sub BuildPresentation()
'Dim pp As PowerPoint.Application
Dim pp As Object
Dim pres1 As PowerPoint.Presentation
Dim pres2 As PowerPoint.Presentation
Dim ppSlides As PowerPoint.Slides
Dim ppSlide As PowerPoint.Slide
Dim newSlide As PowerPoint.Slide
Dim cnt As Integer
Dim i, index, j As Integer
Dim tmp As String
Dim slide As String
Dim num1, num2
Dim oldGatefold, newGatefold As String
Try
'Create a powerpoint object
pp = CreateObject("PowerPoint.Application")
'pp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized
pp.Visible = Office.MsoTriState.msoTrue
pp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized

Application.DoEvents()
Catch ex As Exception
MsgBox("Error opening powerpoint. Error is: " & ex.ToString)
Me.Close()
Exit Sub
End Try

Try

'We have to open this template file so the slides we pull
out
'will have the correct templated scheme
pres2 =
pp.Presentations.Open("C:\DATA\Powerpnt\caps\_tmp. pot")

Catch ex As Exception
MsgBox("Error opening Powerpoint template. Error is: " &
ex.ToString)
Me.Close()
Exit Sub
End Try

'Keep form on top
Me.TopMost = True
Application.DoEvents()

pb1.Maximum = progCnt
lblProgress.Text = "Building Presentation. Please wait..."

' MsgBox("Starting build")

Try
'Slides can be in a number of different gatefolds (different
ppt presentations.
'We cycle through and pull out the slides for each gatefold
and add them
'to a new presentation.
For i = 1 To UBound(arrGateFolds)
tmp = arrGateFolds(i)
pb1.Value = i 'increment progress bar
' MsgBox("tmp: " & tmp)
Application.DoEvents()
If RTrim(tmp) = "" Then Exit For
'The entry will have a gatefold name, space, slide
number
'We need to separate them out
index = InStr(tmp, " ")
newGatefold = Mid(tmp, 1, index - 1)
'MsgBox("Gatefold: " & newGatefold)
slide = RTrim(Mid(tmp, index + 1, 20))
'MsgBox("slide: " & slide)

'If the gatefold name changes we need to close that
'presentation and open the new one.
If newGatefold <> oldGatefold Then
If Not IsNothing(pres1) Then pres1.Close()
pres1 = pp.Presentations.Open(newGatefold)
oldGatefold = newGatefold
End If

'try to pull out the desired slide
Try
ppSlide = pres1.Slides.Item(CInt(slide))
Catch ex As Exception
'must not exist so set slide to nothing
MsgBox("Error opening slide: " & newGatefold & " " &
slide)
ppSlide = Nothing
End Try

'copy and paste the slide to new presentation
If Not IsNothing(ppSlide) Then
pres1.Slides.Item(CInt(slide)).Copy()
pres2.Slides.Paste()
End If
Next

Catch ex As Exception
MsgBox("Error adding slides to new presentation. Error is: "
& ex.ToString)
pres1.Close()
pres2.Close()
pp.Quit()
Me.Close()
Exit Sub
End Try

'Let's delete the first slide as it is the template slide
pres2.Slides.Item(1).Delete()
pres2.SaveAs(ppFileName,
PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Office.MsoTriState.msoTrue)
pp.Windows.Item(2).ViewType =
PowerPoint.PpViewType.ppViewSlideSorter
pres1.Close()
pres2.Save()
pres2.Saved = Office.MsoTriState.msoTrue

'Display that we have saved new presentation
lblProgress.Text = "Presentation saved as: " & ppFileName
Application.DoEvents()
t2.Enabled = True
While t2.Enabled = True
Application.DoEvents()
If t2.Enabled = False Then Exit While
'Just loop here a few seconds to show message.
End While

pp.WindowState = PowerPoint.PpWindowState.ppWindowMaximized
pp.Presentations.Item(1).Saved = Office.MsoTriState.msoTrue
End Sub

presentation names and a slide number is passed into the array.
Something like C:\ppt\sales.ppt 4 means pull the 4th slide out of
this presentation and paste it into the new one.

Thanks for taking the time to look at this.

Rut

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #8

P: n/a

Thanks for trying.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.