Thema Datum  Von Nutzer Rating
Antwort
Rot Export-Makro von Excel nach Powerpoint
21.06.2011 20:56:07 Di!
NotSolved

Ansicht des Beitrags:
Von:
Di!
Datum:
21.06.2011 20:56:07
Views:
2240
Rating: Antwort:
  Ja
Thema:
Export-Makro von Excel nach Powerpoint

Hallo!

Ich habe hier folgenden Code. Er soll per Klick auf einen Button alle Excel-Blätter in PowerPoint als neue Folie einfügen.

Existiert in einem Datenblatt ein Diagramm soll es als eigene Folie hinten dran gehängt werden.

Das funktioniert bei meinem Computer (mit Office 2003) auch. Auf einem anderen (ebenfalls 2003) leider nicht. Und ich kann mir nicht erklären, warum das so ist. :(

Er wirft die Meldung, dass nichts ausgewählt sei bei Zeile 53 ("With .ActiveWindow.Selection.ShapeRange.")

Könnt ihr mir bei der Lösung des Problems helfen, bitte?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
Function GetTemplate()
  View.TextBox1.Text = "D:\SICHER\BK  NEU-ORGA\Vorlage.pot"
End Function
 
Sub CopyWksToPPT()
' Set a VBE reference to Microsoft PowerPoint Object Library
    Dim pptApp As Object
    Dim sTemplatePPt As String
    Dim wks As Worksheet
    Dim sTargetTop As Single
    Dim sTargetLeft As Single
    Dim sTargetWidth As Single
    Dim sTargetHeight As Single
    Dim sScaleHeight As Single
    Dim sScaleWidth As Single
    Dim iIndex As Integer
    Dim c As Integer
 
    'Change these as desired
    sTargetTop = 50
    sTargetLeft = 40
    sTargetWidth = 640
    sTargetHeight = 500
    sTemplatePPt = View.TextBox1.Text
     
    'Check for correct pot Template
    If sTemplatePPt = "" Then
      MsgBox "Bitte ein korrektes Powerpoint-Template angeben!"
    End If
 
    'Open new Powerpoint window
    iIndex = 2
    Set pptApp = CreateObject("Powerpoint.Application")
    With pptApp
        .Visible = True
        .Presentations.Open _
            Filename:=sTemplatePPt, Untitled:=msoTrue
 
        For Each wks In Worksheets
            wks.Select
            .ActiveWindow.View.GotoSlide _
                Index:=.ActivePresentation.Slides.Add _
                (Index:=iIndex, Layout:=ppLayoutTitleOnly).SlideIndex
                 
            'Insert title
            .ActiveWindow.View.Slide.Shapes.Title.TextFrame.TextRange.Text = "Entwicklung " + Replace(ActiveWorkbook.Name, ".xls", "") + " in " + wks.Name
             
            iIndex = iIndex + 1
            wks.UsedRange.Copy
             
            'Insert table
            .ActiveWindow.View.Paste
            With .ActiveWindow.Selection.ShapeRange
                sScaleHeight = sTargetHeight / .Height
                sScaleWidth = sTargetWidth / .Width
                If sScaleHeight < sScaleWidth Then
                    sScaleWidth = sScaleHeight
                Else
                    sScaleHeight = sScaleWidth
                End If
                .ScaleHeight sScaleHeight, 0, 2
                .ScaleWidth sScaleWidth, 0, 2
                .Top = sTargetTop + (sTargetHeight - .Height) / 2
                .Left = sTargetLeft + (sTargetWidth - .Width) / 2
            End With
             
            'Insert possible charts on this worksheet
            '-----------------------------------------
             
            ' Reference existing instance of PowerPoint
            Set PPApp = GetObject(, "Powerpoint.Application")
            ' Reference active presentation
            Set PPPres = PPApp.ActivePresentation
            PPApp.ActiveWindow.ViewType = ppViewSlide
 
            For iCht = 1 To ActiveSheet.ChartObjects.Count
            With ActiveSheet.ChartObjects(iCht).Chart
     
                ' get chart title
                If .HasTitle Then
                    sTitle = .ChartTitle.Text
                Else
                    sTitle = ""
                End If
     
                ' remove title (or it will be redundant)
                .HasTitle = False
                ' copy chart as a picture
                .CopyPicture _
                    Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
                ' restore title
                If Len(sTitle) > 0 Then
                    .HasTitle = True
                    .ChartTitle.Text = sTitle
                End If
            End With
     
            ' Add a new slide and paste in the chart
            Set PPSlide = PPPres.Slides.Add(Index:=iIndex, Layout:=ppLayoutTitleOnly)
            PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex
             
            iIndex = iIndex + 1
     
            With PPSlide
                ' paste and select the chart picture
                .Shapes.Paste.Select
                 
                'scale chart
                With PPApp.ActiveWindow.Selection.ShapeRange
                sScaleHeight = sTargetHeight / .Height
                sScaleWidth = sTargetWidth / .Width
                If sScaleHeight < sScaleWidth Then
                    sScaleWidth = sScaleHeight
                Else
                    sScaleHeight = sScaleWidth
                End If
                .ScaleHeight sScaleHeight, 0, 2
                .ScaleWidth sScaleWidth, 0, 2
                .Top = sTargetTop + (sTargetHeight - .Height) / 2
                .Left = sTargetLeft + (sTargetWidth - .Width) / 2
                End With
                 
                .Shapes.Placeholders(1).TextFrame.TextRange.Text = sTitle
            End With
            Next
 
            '---------------------------
            'END CHARTS
             
        Next
        .Visible = True
         
        'Go back to first Slide and fill in Title
        .ActiveWindow.View.GotoSlide 1
        .ActiveWindow.View.Slide.Shapes.Title.TextFrame.TextRange.Text = Replace(ActiveWorkbook.Name, ".xls", "")
    End With
     
End Sub
 
Sub Auto_Open()
  View.Show
  GetTemplate
End Sub
 
Function CopyCharts(PPPres As PowerPoint.Application)
 
  For iCht = 1 To ActiveSheet.ChartObjects.Count
    With ActiveSheet.ChartObjects(iCht).Chart
     
    ' get chart title
    If .HasTitle Then
        sTitle = .ChartTitle.Text
    Else
        sTitle = ""
    End If
     
    ' remove title (or it will be redundant)
    .HasTitle = False
    ' copy chart as a picture
    .CopyPicture _
        Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
    ' restore title
    If Len(sTitle) > 0 Then
        .HasTitle = True
        .ChartTitle.Text = sTitle
    End If
    End With
     
    ' Add a new slide and paste in the chart
    SlideCount = PPPres.Slides.Count
    Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutTitleOnly)
    PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex
     
    With PPSlide
        ' paste and select the chart picture
        .Shapes.Paste.Select
        ' align the chart
        PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
        PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
        .Shapes.Placeholders(1).TextFrame.TextRange.Text = sTitle
    End With
  Next
 
End Function

 


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
Rot Export-Makro von Excel nach Powerpoint
21.06.2011 20:56:07 Di!
NotSolved