Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1868to1872
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
VBA PowerPoint Mappe aktivieren
11.02.2022 09:55:17
Marenweißnichtweiter
Hallo zusammen,
ich versuche eine PowerPoint-Präsentation, welche im Hintergrund liegt zu aktivieren. Ich habe schon einige Sachen ausprobiert, diese sind unten im Text auskommentiert.
Ganz konkret: Die Präsentation "pre" ist geöffnet. Ich öffne die "preOutput", um dort die Folien raus zu kopieren und muss dann "pre" aktivieren, um die Folien einfügen zu können. Wie schaffe ich es "pre" zu aktivieren?

Sub ExporttoPPT()
'1. Variablen deklarieren
Dim ppt_app As New PowerPoint.Application
Dim pre As PowerPoint.Presentation
Dim slde As PowerPoint.slide
Dim shp As PowerPoint.Shape
Dim wb As Workbook
Dim rng As Range
Dim vSheet$
Dim vRange$
Dim vWidth As Double
Dim vHeight As Double
Dim vTop As Double
Dim vLeft As Double
Dim vSlide_No As Long
Dim expRng As Range
Dim adminSh As Worksheet
Dim cofigRng As Range
Dim xlfile$
Dim pptfile$
Dim pptfile2$
Dim preOutput As PowerPoint.Presentation
Dim sldOutputNeu As PowerPoint.slide
Dim sldOutputAlt As PowerPoint.slide
Dim varPfadPräsi
Dim intFolieOutput As Integer
Dim intFolieSteuer As Integer
'Möchten sie speichern? Wird ausgeschalten
Application.DisplayAlerts = False
'2.Variablen füllen
Set adminSh = ThisWorkbook.Sheets("Admin")
Set cofigRng = adminSh.Range("Rng_sheets")
xlfile = adminSh.[excelPth]
pptfile = adminSh.[pptPth]
pptfile2 = adminSh.[pptPth2]
'3. Varibalen verarbeiten
'3.1 Grafiken aus Excel in PP einfügen
Set pre = ppt_app.Presentations.Open(pptfile) 'PP ("Vorlage Charts Dortmund") wird geöffnet und der Variable pre zugeordnet
pre.SaveCopyAs pptfile2 'PP unter anderem Namen abspreichern (dieser wird in der Excel manuell vergeben)
pre.Close 'ursprüngliche PP schließen
Set wb = Workbooks.Open(xlfile) 'Ecel Datei aus der die Grafiken kopiert werden öffnen
Set pre = ppt_app.Presentations.Open(pptfile2) 'PP unter neuem Namen öffnen
For Each rng In cofigRng
'--------------------------Set Variables (Variablen mir Werten füllen)
With adminSh
vSheet$ = .Cells(rng.Row, 4).Value
vRange$ = .Cells(rng.Row, 5).Value
vWidth = .Cells(rng.Row, 6).Value
vHeight = .Cells(rng.Row, 7).Value
vTop = .Cells(rng.Row, 8).Value
vLeft = .Cells(rng.Row, 9).Value
vSlide_No = .Cells(rng.Row, 10).Value
End With
'----------------------------Export to PPT
wb.Activate
Sheets(vSheet$).Activate
Set expRng = Sheets(vSheet$).Range(vRange$) 'expRng mit den voreingetstellten Ranges in Excel (aka Grafiken) fülle
expRng.Copy
Set slde = pre.Slides(vSlide_No)
slde.Shapes.PasteSpecial DataType:=ppPasteEnhancedMetafile
Set shp = slde.Shapes("Grafik 2")
With shp
.Top = vTop
.Left = vLeft
.Width = vWidth
.Height = vHeight
End With
Set shp = Nothing
Set slde = Nothing
Set expRng = Sheets(vSheet$).Range(vRange$)
Application.CutCopyMode = False
Set expRng = Nothing
Next rng
'3.2 PP Folie aus anderer PP in aktueller PP ersetzten
'pptfile = adminSh.[pptPth]
varPfadPräsi = adminSh.[pptpthOutput]
intFolieOutput = adminSh.[FolieOutput]
intFolieSteuer = adminSh.[FolieSteuer]
Debug.Print intFolieSteuer
Set preOutput = ppt_app.Presentations.Open(varPfadPräsi)
ppt_app.ActivePresentation.Slides.Range(11).Select
ppt_app.ActivePresentation.Slides(11).Copy
'preOutput.Visible = False
'Presentation(pre).Activate
'        With ppt_app.pre
'            .Visible = msoTrue
'            .Activate
'        End With
'        With ppt_app.Presentations(pre).Windows(1)
'            If Not .Active Then
'                Set oldwin = Application.ActiveWindow
'                .Activate
'            End If
'        End With
'Set pre = ppt_app.ActivePresentation
'pre (msoBringToFront)
'preOutput.Visible = msoFalse
'pre.Activate
'ppt_app.pre.Activate
ppt_app.ActivePresentation.Slides.Paste 13
ppt_app.ActivePresentation.Slides(14).Delete
preOutput.Close
pre.Save
pre.Close
Set pre = Nothing
Set ppt_app = Nothing
wb.Close False
Set wb = Nothing
Application.DisplayAlerts = True
MsgBox "Präsentation wurde erstellt"
End Sub

6
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Antonioauchnicht
11.02.2022 10:07:07
Antonio
:-)
AW: VBA PowerPoint Mappe aktivieren
11.02.2022 10:25:06
Nepumuk
Hallo Maren,
teste mal:

Option Explicit
Private Declare PtrSafe Function FindWindowA Lib "user32.dll" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function ShowWindow Lib "user32.dll" ( _
ByVal hwnd As LongPtr, _
ByVal nCmdShow As Long) As Long
Private Declare PtrSafe Function GetWindowThreadProcessId Lib "user32.dll" ( _
ByVal hwnd As LongPtr, _
ByRef lpdwProcessId As Long) As Long
Private Declare PtrSafe Function AllowSetForegroundWindow Lib "user32.dll" ( _
ByVal dwProcessId As Long) As Long
Private Declare PtrSafe Function SetForegroundWindow Lib "user32.dll" ( _
ByVal hwnd As LongPtr) As Long
Private Const GC_CLASSNAMEPOWERPOINT = "PPTFrameClass"
Private Const SW_SHOW As Long = 5
Public Sub PowerPointToForeground()
Dim lngptrHwnd As LongPtr, lngProcessID As Long
lngptrHwnd = FindWindowA(GC_CLASSNAMEPOWERPOINT, vbNullString)
If lngptrHwnd = 0 Then Call Err.Raise(Number:=vbObjectError, Description:= _
"Das Fensterhandle von PowerPoint kann nicht ermittelt werden.")
lngProcessID = GetWindowThreadProcessId(lngptrHwnd, ByVal 0&)
Call AllowSetForegroundWindow(lngProcessID)
Call SetForegroundWindow(lngptrHwnd)
Call ShowWindow(lngptrHwnd, SW_SHOW)
End Sub
Gruß
Nepumuk
Anzeige
AW: VBA PowerPoint Mappe aktivieren
11.02.2022 11:14:31
Marenweißnichtweiter
Hallo Nepumuk,
leider verstehe ich deinen Code nicht richtig. Kannst du mir sagen an welcher Stelle ich diesen einfügen muss?
Danke.
AW: VBA PowerPoint Mappe aktivieren
11.02.2022 11:20:44
Nepumuk
Hallo Maren,
da:

MsgBox "Präsentation wurde erstellt"
Call PowerPointToForeground
End Sub
Das kommt ganz oben in das Modul:

Option Explicit
Private Declare PtrSafe Function FindWindowA Lib "user32.dll" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function ShowWindow Lib "user32.dll" ( _
ByVal hwnd As LongPtr, _
ByVal nCmdShow As Long) As Long
Private Declare PtrSafe Function GetWindowThreadProcessId Lib "user32.dll" ( _
ByVal hwnd As LongPtr, _
ByRef lpdwProcessId As Long) As Long
Private Declare PtrSafe Function AllowSetForegroundWindow Lib "user32.dll" ( _
ByVal dwProcessId As Long) As Long
Private Declare PtrSafe Function SetForegroundWindow Lib "user32.dll" ( _
ByVal hwnd As LongPtr) As Long
Private Const GC_CLASSNAMEPOWERPOINT = "PPTFrameClass"
Private Const SW_SHOW As Long = 5
Gruß
Nepumuk
Anzeige
AW: VBA PowerPoint Mappe aktivieren
11.02.2022 11:30:28
Marenweißnichtweiter
Hallo Nepumuk,
die Applikation PP ist ja insgesamt schon im Vordergrund, da aber die falsche Präsentation (preOutput) die Active Präsentation ist, kann ich nicht in die richtige Präsentation (pre) einfügen. Ich muss also eine Powerpoint Präsentation aktivieren, nicht die PowerPoint Applikation.
Ich brauche also (meines Verständnis nach) Code nach:
ppt_app.ActivePresentation.Slides.Range(11).Select
ppt_app.ActivePresentation.Slides(11).Copy
AW: VBA PowerPoint Mappe aktivieren
11.02.2022 12:13:57
Nepumuk
Hallo Maren,
da kann ich dir nicht weiter helfen, dazu kenne ich mich mit PowerPoint zu wenig aus.
Ich lass die Frage offen.
Gruß
Nepumuk
Anzeige

43 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige