Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Error setting GUID reference

Hi,

I have the following queries with reference to the code modules below :

1) If I first run SetMyRef and then run ExcelChartsToPPT, it works fine. But
if I *call* SetMyRef from the second module the reference to Powerpoint is
not set, and the code aborts. Why is this so ?
2) How should I change my code to late binding for ExcelChartsToPPT ?

Option Explicit

Sub SetMyRef()
Dim R As Variant

For Each R In ActiveWorkbook.VBProject.References
If R.GUID = "{91493440-5A91-11CF-8700-00AA0060263B}" Then
Exit Sub
End If
Next

On Error GoTo NotFound

ActiveWorkbook.VBProject.References.AddFromGuid
"{91493440-5A91-11CF-8700-00AA0060263B}", _
Major:=2, Minor:=7

Exit Sub

NotFound:
MsgBox "CAN'T RUN THIS CODE"

End Sub

Sub ExcelChartsToPPT()

On Error GoTo ErrHandler

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim SlideCount As Long
Dim iCht As Integer
Dim i As Integer
Dim Ans As String


Ans = MsgBox("Copy all charts in workbook to Powerpoint ?", vbYesNo +
vbQuestion, "Confirm")
If Ans = vbYes Then GoTo Proceed Else Exit Sub

Proceed:
Set PPApp = CreateObject("Powerpoint.Application")
PPApp.Visible = True
PPApp.WindowState = ppWindowMinimized

' Create active presentation
Set PPPres = PPApp.Presentations.Add
PPPres.Slides.Add 1, ppLayoutTitle

For i = 1 To Worksheets.Count 'All worksheets with embedded charts
needing transfer to PP
For iCht = 1 To Worksheets(i).ChartObjects.Count
' copy chart as a picture
Worksheets(i).ChartObjects(iCht).Chart.CopyPicture _
Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
'xlBitmap can also be used

' Add a new slide and paste in the chart
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutBlank)
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

End With

Next iCht
Next i

PPPres.Slides(1).Select
PPApp.WindowState = ppWindowMaximized

' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

Exit Sub

ErrHandler: MsgBox "An error occurred; please re-try !", vbInformation

End Sub


Thanks,
Amit



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Error setting GUID reference

Amit,

Using VBA code to modify code in the same workbook is
problematic, e.g., when is such code compiled. If you can bind
to the PowerPoint reference at design time, I would use late
binding and bypass all the issues with the PowerPoint reference
completely. Just change any variable declared "As
PowerPoint.Whatever" to "As Object". If you use enum constants
from the PPT library, you'll have to change those to their
literal values.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Amit Shanker" wrote in message
...
Hi,

I have the following queries with reference to the code modules

below :

1) If I first run SetMyRef and then run ExcelChartsToPPT, it

works fine. But
if I *call* SetMyRef from the second module the reference to

Powerpoint is
not set, and the code aborts. Why is this so ?
2) How should I change my code to late binding for

ExcelChartsToPPT ?

Option Explicit

Sub SetMyRef()
Dim R As Variant

For Each R In ActiveWorkbook.VBProject.References
If R.GUID = "{91493440-5A91-11CF-8700-00AA0060263B}"

Then
Exit Sub
End If
Next

On Error GoTo NotFound

ActiveWorkbook.VBProject.References.AddFromGuid
"{91493440-5A91-11CF-8700-00AA0060263B}", _
Major:=2, Minor:=7

Exit Sub

NotFound:
MsgBox "CAN'T RUN THIS CODE"

End Sub

Sub ExcelChartsToPPT()

On Error GoTo ErrHandler

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim SlideCount As Long
Dim iCht As Integer
Dim i As Integer
Dim Ans As String


Ans = MsgBox("Copy all charts in workbook to Powerpoint ?",

vbYesNo +
vbQuestion, "Confirm")
If Ans = vbYes Then GoTo Proceed Else Exit Sub

Proceed:
Set PPApp = CreateObject("Powerpoint.Application")
PPApp.Visible = True
PPApp.WindowState = ppWindowMinimized

' Create active presentation
Set PPPres = PPApp.Presentations.Add
PPPres.Slides.Add 1, ppLayoutTitle

For i = 1 To Worksheets.Count 'All worksheets with

embedded charts
needing transfer to PP
For iCht = 1 To Worksheets(i).ChartObjects.Count
' copy chart as a picture
Worksheets(i).ChartObjects(iCht).Chart.CopyPicture

_
Appearance:=xlScreen, Size:=xlScreen,

Format:=xlPicture
'xlBitmap can also be used

' Add a new slide and paste in the chart
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1,

ppLayoutBlank)
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

End With

Next iCht
Next i

PPPres.Slides(1).Select
PPApp.WindowState = ppWindowMaximized

' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

Exit Sub

ErrHandler: MsgBox "An error occurred; please re-try !",

vbInformation

End Sub


Thanks,
Amit





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Error setting GUID reference

Thanks Chip, I will try and go down the late binding route as per your
suggestion. But as an alternative, does it mean that I can set reference
with my original code if I am using it from another workbook ?

"Chip Pearson" wrote in message
...
Amit,

Using VBA code to modify code in the same workbook is
problematic, e.g., when is such code compiled. If you can bind
to the PowerPoint reference at design time, I would use late
binding and bypass all the issues with the PowerPoint reference
completely. Just change any variable declared "As
PowerPoint.Whatever" to "As Object". If you use enum constants
from the PPT library, you'll have to change those to their
literal values.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Amit Shanker" wrote in message
...
Hi,

I have the following queries with reference to the code modules

below :

1) If I first run SetMyRef and then run ExcelChartsToPPT, it

works fine. But
if I *call* SetMyRef from the second module the reference to

Powerpoint is
not set, and the code aborts. Why is this so ?
2) How should I change my code to late binding for

ExcelChartsToPPT ?

Option Explicit

Sub SetMyRef()
Dim R As Variant

For Each R In ActiveWorkbook.VBProject.References
If R.GUID = "{91493440-5A91-11CF-8700-00AA0060263B}"

Then
Exit Sub
End If
Next

On Error GoTo NotFound

ActiveWorkbook.VBProject.References.AddFromGuid
"{91493440-5A91-11CF-8700-00AA0060263B}", _
Major:=2, Minor:=7

Exit Sub

NotFound:
MsgBox "CAN'T RUN THIS CODE"

End Sub

Sub ExcelChartsToPPT()

On Error GoTo ErrHandler

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim SlideCount As Long
Dim iCht As Integer
Dim i As Integer
Dim Ans As String


Ans = MsgBox("Copy all charts in workbook to Powerpoint ?",

vbYesNo +
vbQuestion, "Confirm")
If Ans = vbYes Then GoTo Proceed Else Exit Sub

Proceed:
Set PPApp = CreateObject("Powerpoint.Application")
PPApp.Visible = True
PPApp.WindowState = ppWindowMinimized

' Create active presentation
Set PPPres = PPApp.Presentations.Add
PPPres.Slides.Add 1, ppLayoutTitle

For i = 1 To Worksheets.Count 'All worksheets with

embedded charts
needing transfer to PP
For iCht = 1 To Worksheets(i).ChartObjects.Count
' copy chart as a picture
Worksheets(i).ChartObjects(iCht).Chart.CopyPicture

_
Appearance:=xlScreen, Size:=xlScreen,

Format:=xlPicture
'xlBitmap can also be used

' Add a new slide and paste in the chart
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1,

ppLayoutBlank)
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

End With

Next iCht
Next i

PPPres.Slides(1).Select
PPApp.WindowState = ppWindowMaximized

' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

Exit Sub

ErrHandler: MsgBox "An error occurred; please re-try !",

vbInformation

End Sub


Thanks,
Amit







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Error setting GUID reference

You should be able to do that. There are still issues of when the
revised project gets compiled (before or after the reference has
been added). Adding references on the fly is something I haven't
done much work with, so I'm no expert on the perils of doing so.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Amit Shanker" wrote in message
...
Thanks Chip, I will try and go down the late binding route as

per your
suggestion. But as an alternative, does it mean that I can set

reference
with my original code if I am using it from another workbook ?

"Chip Pearson" wrote in message
...
Amit,

Using VBA code to modify code in the same workbook is
problematic, e.g., when is such code compiled. If you can

bind
to the PowerPoint reference at design time, I would use late
binding and bypass all the issues with the PowerPoint

reference
completely. Just change any variable declared "As
PowerPoint.Whatever" to "As Object". If you use enum

constants
from the PPT library, you'll have to change those to their
literal values.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Amit Shanker" wrote in

message
...
Hi,

I have the following queries with reference to the code

modules
below :

1) If I first run SetMyRef and then run ExcelChartsToPPT,

it
works fine. But
if I *call* SetMyRef from the second module the reference

to
Powerpoint is
not set, and the code aborts. Why is this so ?
2) How should I change my code to late binding for

ExcelChartsToPPT ?

Option Explicit

Sub SetMyRef()
Dim R As Variant

For Each R In ActiveWorkbook.VBProject.References
If R.GUID =

"{91493440-5A91-11CF-8700-00AA0060263B}"
Then
Exit Sub
End If
Next

On Error GoTo NotFound

ActiveWorkbook.VBProject.References.AddFromGuid
"{91493440-5A91-11CF-8700-00AA0060263B}", _
Major:=2, Minor:=7

Exit Sub

NotFound:
MsgBox "CAN'T RUN THIS CODE"

End Sub

Sub ExcelChartsToPPT()

On Error GoTo ErrHandler

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim SlideCount As Long
Dim iCht As Integer
Dim i As Integer
Dim Ans As String


Ans = MsgBox("Copy all charts in workbook to Powerpoint

?",
vbYesNo +
vbQuestion, "Confirm")
If Ans = vbYes Then GoTo Proceed Else Exit Sub

Proceed:
Set PPApp = CreateObject("Powerpoint.Application")
PPApp.Visible = True
PPApp.WindowState = ppWindowMinimized

' Create active presentation
Set PPPres = PPApp.Presentations.Add
PPPres.Slides.Add 1, ppLayoutTitle

For i = 1 To Worksheets.Count 'All worksheets with

embedded charts
needing transfer to PP
For iCht = 1 To Worksheets(i).ChartObjects.Count
' copy chart as a picture

Worksheets(i).ChartObjects(iCht).Chart.CopyPicture
_
Appearance:=xlScreen, Size:=xlScreen,

Format:=xlPicture
'xlBitmap can also be used

' Add a new slide and paste in the chart
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1,

ppLayoutBlank)
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

End With

Next iCht
Next i

PPPres.Slides(1).Select
PPApp.WindowState = ppWindowMaximized

' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

Exit Sub

ErrHandler: MsgBox "An error occurred; please re-try

!",
vbInformation

End Sub


Thanks,
Amit









  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Error setting GUID reference

Chip, another question if I may - is the GUID reference independent of
Office and Windows version ? I have not been able to find a definitive
answer.


"Chip Pearson" wrote in message
...
You should be able to do that. There are still issues of when the
revised project gets compiled (before or after the reference has
been added). Adding references on the fly is something I haven't
done much work with, so I'm no expert on the perils of doing so.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Amit Shanker" wrote in message
...
Thanks Chip, I will try and go down the late binding route as

per your
suggestion. But as an alternative, does it mean that I can set

reference
with my original code if I am using it from another workbook ?

"Chip Pearson" wrote in message
...
Amit,

Using VBA code to modify code in the same workbook is
problematic, e.g., when is such code compiled. If you can

bind
to the PowerPoint reference at design time, I would use late
binding and bypass all the issues with the PowerPoint

reference
completely. Just change any variable declared "As
PowerPoint.Whatever" to "As Object". If you use enum

constants
from the PPT library, you'll have to change those to their
literal values.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Amit Shanker" wrote in

message
...
Hi,

I have the following queries with reference to the code

modules
below :

1) If I first run SetMyRef and then run ExcelChartsToPPT,

it
works fine. But
if I *call* SetMyRef from the second module the reference

to
Powerpoint is
not set, and the code aborts. Why is this so ?
2) How should I change my code to late binding for
ExcelChartsToPPT ?

Option Explicit

Sub SetMyRef()
Dim R As Variant

For Each R In ActiveWorkbook.VBProject.References
If R.GUID =

"{91493440-5A91-11CF-8700-00AA0060263B}"
Then
Exit Sub
End If
Next

On Error GoTo NotFound

ActiveWorkbook.VBProject.References.AddFromGuid
"{91493440-5A91-11CF-8700-00AA0060263B}", _
Major:=2, Minor:=7

Exit Sub

NotFound:
MsgBox "CAN'T RUN THIS CODE"

End Sub

Sub ExcelChartsToPPT()

On Error GoTo ErrHandler

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim SlideCount As Long
Dim iCht As Integer
Dim i As Integer
Dim Ans As String


Ans = MsgBox("Copy all charts in workbook to Powerpoint

?",
vbYesNo +
vbQuestion, "Confirm")
If Ans = vbYes Then GoTo Proceed Else Exit Sub

Proceed:
Set PPApp = CreateObject("Powerpoint.Application")
PPApp.Visible = True
PPApp.WindowState = ppWindowMinimized

' Create active presentation
Set PPPres = PPApp.Presentations.Add
PPPres.Slides.Add 1, ppLayoutTitle

For i = 1 To Worksheets.Count 'All worksheets with
embedded charts
needing transfer to PP
For iCht = 1 To Worksheets(i).ChartObjects.Count
' copy chart as a picture

Worksheets(i).ChartObjects(iCht).Chart.CopyPicture
_
Appearance:=xlScreen, Size:=xlScreen,
Format:=xlPicture
'xlBitmap can also be used

' Add a new slide and paste in the chart
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1,
ppLayoutBlank)
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

End With

Next iCht
Next i

PPPres.Slides(1).Select
PPApp.WindowState = ppWindowMaximized

' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

Exit Sub

ErrHandler: MsgBox "An error occurred; please re-try

!",
vbInformation

End Sub


Thanks,
Amit













  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Error setting GUID reference

Hi Amit,

Amit Shanker wrote:
I have the following queries with reference to the code modules below :

1) If I first run SetMyRef and then run ExcelChartsToPPT, it works fine. But
if I *call* SetMyRef from the second module the reference to Powerpoint is
not set, and the code aborts. Why is this so ?
2) How should I change my code to late binding for ExcelChartsToPPT ?


replace the constants from PowerPoint by its values:

Sub ExcelChartsToPPT()
Dim PPApp As Object
Dim PPPres As Object
Dim PPSlide As Object
Dim iCht As Integer
Dim i As Integer

If MsgBox("Copy all charts in workbook to Powerpoint ?", _
vbYesNo + vbQuestion, "Confirm") = vbNo Then Exit Sub

Set PPApp = CreateObject("Powerpoint.Application")
PPApp.Visible = True
PPApp.WindowState = 2 'ppWindowMinimized

' Create active presentation
Set PPPres = PPApp.Presentations.Add
PPPres.Slides.Add 1, 1 ' ppLayoutTitle

For i = 1 To Worksheets.Count
For iCht = 1 To Worksheets(i).ChartObjects.Count
' copy chart as a picture
Worksheets(i).ChartObjects(iCht).Chart.CopyPicture _
Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
' Add a new slide and paste in the chart
Set PPSlide = PPPres.Slides.Add(PPPres.Slides.Count + 1, 12) 'ppLayoutBlank)
PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex
' paste and select the chart picture
PPSlide.Shapes.Paste.Select
' align the chart
With PPApp.ActiveWindow.Selection.ShapeRange
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
End With
Next iCht
Next i

PPPres.Slides(1).Select
PPApp.WindowState = 3 'ppWindowMaximized
End Sub

--
Regards
Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Error setting GUID reference

Yes.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Amit Shanker" wrote in message
...
Chip, another question if I may - is the GUID reference

independent of
Office and Windows version ? I have not been able to find a

definitive
answer.


"Chip Pearson" wrote in message
...
You should be able to do that. There are still issues of when

the
revised project gets compiled (before or after the reference

has
been added). Adding references on the fly is something I

haven't
done much work with, so I'm no expert on the perils of doing

so.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Amit Shanker" wrote in

message
...
Thanks Chip, I will try and go down the late binding route

as
per your
suggestion. But as an alternative, does it mean that I can

set
reference
with my original code if I am using it from another

workbook ?

"Chip Pearson" wrote in message
...
Amit,

Using VBA code to modify code in the same workbook is
problematic, e.g., when is such code compiled. If you

can
bind
to the PowerPoint reference at design time, I would use

late
binding and bypass all the issues with the PowerPoint

reference
completely. Just change any variable declared "As
PowerPoint.Whatever" to "As Object". If you use enum

constants
from the PPT library, you'll have to change those to

their
literal values.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Amit Shanker" wrote in

message
...
Hi,

I have the following queries with reference to the code

modules
below :

1) If I first run SetMyRef and then run

ExcelChartsToPPT,
it
works fine. But
if I *call* SetMyRef from the second module the

reference
to
Powerpoint is
not set, and the code aborts. Why is this so ?
2) How should I change my code to late binding for
ExcelChartsToPPT ?

Option Explicit

Sub SetMyRef()
Dim R As Variant

For Each R In ActiveWorkbook.VBProject.References
If R.GUID =

"{91493440-5A91-11CF-8700-00AA0060263B}"
Then
Exit Sub
End If
Next

On Error GoTo NotFound

ActiveWorkbook.VBProject.References.AddFromGuid
"{91493440-5A91-11CF-8700-00AA0060263B}", _
Major:=2, Minor:=7

Exit Sub

NotFound:
MsgBox "CAN'T RUN THIS CODE"

End Sub

Sub ExcelChartsToPPT()

On Error GoTo ErrHandler

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim SlideCount As Long
Dim iCht As Integer
Dim i As Integer
Dim Ans As String


Ans = MsgBox("Copy all charts in workbook to

Powerpoint
?",
vbYesNo +
vbQuestion, "Confirm")
If Ans = vbYes Then GoTo Proceed Else Exit Sub

Proceed:
Set PPApp = CreateObject("Powerpoint.Application")
PPApp.Visible = True
PPApp.WindowState = ppWindowMinimized

' Create active presentation
Set PPPres = PPApp.Presentations.Add
PPPres.Slides.Add 1, ppLayoutTitle

For i = 1 To Worksheets.Count 'All worksheets

with
embedded charts
needing transfer to PP
For iCht = 1 To

Worksheets(i).ChartObjects.Count
' copy chart as a picture

Worksheets(i).ChartObjects(iCht).Chart.CopyPicture
_
Appearance:=xlScreen, Size:=xlScreen,
Format:=xlPicture
'xlBitmap can also be used

' Add a new slide and paste in the chart
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount

+ 1,
ppLayoutBlank)
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

End With

Next iCht
Next i

PPPres.Slides(1).Select
PPApp.WindowState = ppWindowMaximized

' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

Exit Sub

ErrHandler: MsgBox "An error occurred; please

re-try
!",
vbInformation

End Sub


Thanks,
Amit













  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Error setting GUID reference

Melanie, thank you very much. Works beautifully !

"Melanie Breden" wrote in message
...
Hi Amit,

Amit Shanker wrote:
I have the following queries with reference to the code modules below :

1) If I first run SetMyRef and then run ExcelChartsToPPT, it works fine.

But
if I *call* SetMyRef from the second module the reference to Powerpoint

is
not set, and the code aborts. Why is this so ?
2) How should I change my code to late binding for ExcelChartsToPPT ?


replace the constants from PowerPoint by its values:

Sub ExcelChartsToPPT()
Dim PPApp As Object
Dim PPPres As Object
Dim PPSlide As Object
Dim iCht As Integer
Dim i As Integer

If MsgBox("Copy all charts in workbook to Powerpoint ?", _
vbYesNo + vbQuestion, "Confirm") = vbNo Then Exit Sub

Set PPApp = CreateObject("Powerpoint.Application")
PPApp.Visible = True
PPApp.WindowState = 2 'ppWindowMinimized

' Create active presentation
Set PPPres = PPApp.Presentations.Add
PPPres.Slides.Add 1, 1 ' ppLayoutTitle

For i = 1 To Worksheets.Count
For iCht = 1 To Worksheets(i).ChartObjects.Count
' copy chart as a picture
Worksheets(i).ChartObjects(iCht).Chart.CopyPicture _
Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
' Add a new slide and paste in the chart
Set PPSlide = PPPres.Slides.Add(PPPres.Slides.Count + 1, 12)

'ppLayoutBlank)
PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex
' paste and select the chart picture
PPSlide.Shapes.Paste.Select
' align the chart
With PPApp.ActiveWindow.Selection.ShapeRange
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
End With
Next iCht
Next i

PPPres.Slides(1).Select
PPApp.WindowState = 3 'ppWindowMaximized
End Sub

--
Regards
Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create A GUID Derek Hart Excel Worksheet Functions 3 December 24th 07 01:30 AM
Setting GUID reference error Amit Shanker Excel Programming 0 May 15th 04 02:33 PM
.dll and GUID Ross[_7_] Excel Programming 0 May 12th 04 03:56 PM
How retrieve GUID and Document Properties Bob Phillips[_6_] Excel Programming 1 May 5th 04 04:56 PM
Possible to generate a GUID in Excel? Dan[_29_] Excel Programming 2 January 6th 04 06:30 AM


All times are GMT +1. The time now is 11:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"