PDA

View Full Version : Compile error in hidden module



tommy1234
02-22-2012, 03:50 PM
Hello
I create an excel file with many macros (office 2010) and secure structure and sheets.
the file location is on the web so many users can reach it.
several users have office 2007 and they get an error message :
"Compile error in hidden module"
when i checked the preferences fund out that there is a problem with Microsoft power point object library version.
is there a option to solve this problem with code ? or how can i fix it that every user with office 2007 won't get this error ?

thanks

Bob Phillips
02-22-2012, 05:18 PM
Yeah, use late binding. Show us your code where you use the PowerPoint object.

raji2678
02-22-2012, 09:44 PM
Can you try On Error Resume Next?

tommy1234
02-23-2012, 12:12 AM
here's my code that cause the error :

Sub copy_ppt()
'copy the dashboard to a new ppt slide with positioning
Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim lines As String, lines1 As String, lines2 As String
' Reference instance of PowerPoint
On Error Resume Next
' Check whether PowerPoint is running
Set PPApp = GetObject(, "PowerPoint.Application")
If PPApp Is Nothing Then
' PowerPoint is not running, create new instance
Set PPApp = CreateObject("PowerPoint.Application")
' For automation to work, PowerPoint must be visible
PPApp.Visible = True
End If
On Error GoTo 0
' Reference presentation and slide
On Error Resume Next
If PPApp.Windows.Count > 0 Then
' There is at least one presentation
' Use existing presentation
Set PPPres = PPApp.ActivePresentation
' Use active slide
Set PPSlide = PPPres.Slides _
(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
Else
' There are no presentations
' Create new presentation
Set PPPres = PPApp.Presentations.Add
' Add first slide
Set PPSlide = PPPres.Slides.Add(1, ppLayoutTitleOnly)
PPSlide.Shapes(1).TextFrame.textRange = "Project Dashboard Status" & " " & Format(Worksheets("pivot") _
.Range("b321"), "mm/yyyy")
End If
On Error GoTo 0
' Some PowerPoint actions work best in normal slide view
PPApp.ActiveWindow.ViewType = ppViewSlide
Sheets("Dashboard").Select
Range("e1:r39").Select

' Copy the range as a picture
Selection.CopyPicture Appearance:=xlScreen, _
Format:=xlPicture
' Paste the range with positioning
With PPSlide.Shapes.Paste
.Top = 60
.Left = 60
.Width = 600
.Height = 465
End With
Set PPSlide = PPPres.Slides.Add(2, ppLayoutTitleOnly)
PPSlide.Shapes(1).TextFrame.textRange = "Dashboard Analysis" & " " & Format(Worksheets("pivot") _
.Range("b321"), "mm/yyyy")
' Some PowerPoint actions work best in normal slide view
PPApp.ActiveWindow.ViewType = ppViewSlide
Sheets("Dashboard").Select
Range("e40:r72").Select

' Copy the range as a picture
Selection.CopyPicture Appearance:=xlScreen, _
Format:=xlPicture
' Paste the range with positioning
With PPSlide.Shapes.Paste
.Top = 80
.Left = 20
.Width = 600
.Height = 420
End With


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

Cells(1, 18).Select
End Sub

frank_m
02-23-2012, 12:20 AM
Can you try On Error Resume Next?
Hi raji2678,

Doing that wouldn't do anything when there is a compile error.

tommy1234
02-23-2012, 01:34 AM
what can i do with the compile error ?

Bob Phillips
02-23-2012, 02:06 AM
This should do it




Sub copy_ppt()
Const ppLayoutTitleOnly As Long = 11
'copy the dashboard to a new ppt slide with positioning
Dim PPApp As Object 'PowerPoint.Application
Dim PPPres As Object 'PowerPoint.Presentation
Dim PPSlide As Object 'PowerPoint.Slide
Dim lines As String, lines1 As String, lines2 As String
' Reference instance of PowerPoint
On Error Resume Next
' Check whether PowerPoint is running
Set PPApp = GetObject(, "PowerPoint.Application")
If PPApp Is Nothing Then
' PowerPoint is not running, create new instance
Set PPApp = CreateObject("PowerPoint.Application")
' For automation to work, PowerPoint must be visible
PPApp.Visible = True
End If
On Error GoTo 0
' Reference presentation and slide
On Error Resume Next
If PPApp.Windows.Count > 0 Then
' There is at least one presentation
' Use existing presentation
Set PPPres = PPApp.ActivePresentation
' Use active slide
Set PPSlide = PPPres.Slides _
(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
Else
' There are no presentations
' Create new presentation
Set PPPres = PPApp.Presentations.Add
' Add first slide
Set PPSlide = PPPres.Slides.Add(1, ppLayoutTitleOnly)
PPSlide.Shapes(1).TextFrame.TextRange = "Project Dashboard Status" & " " & Format(Worksheets("pivot") _
.Range("b321"), "mm/yyyy")
End If
On Error GoTo 0
' Some PowerPoint actions work best in normal slide view
PPApp.ActiveWindow.ViewType = ppViewSlide
Sheets("Dashboard").Select
Range("e1:r39").Select

' Copy the range as a picture
Selection.CopyPicture Appearance:=xlScreen, _
Format:=xlPicture
' Paste the range with positioning
With PPSlide.Shapes.Paste
.Top = 60
.Left = 60
.Width = 600
.Height = 465
End With
Set PPSlide = PPPres.Slides.Add(2, ppLayoutTitleOnly)
PPSlide.Shapes(1).TextFrame.TextRange = "Dashboard Analysis" & " " & Format(Worksheets("pivot") _
.Range("b321"), "mm/yyyy")
' Some PowerPoint actions work best in normal slide view
PPApp.ActiveWindow.ViewType = ppViewSlide
Sheets("Dashboard").Select
Range("e40:r72").Select

' Copy the range as a picture
Selection.CopyPicture Appearance:=xlScreen, _
Format:=xlPicture
' Paste the range with positioning
With PPSlide.Shapes.Paste
.Top = 80
.Left = 20
.Width = 600
.Height = 420
End With


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

Cells(1, 18).Select
End Sub

raji2678
02-23-2012, 04:10 AM
Can you please attach the Excel code as well? That is, if the problem is not solved as yet.

tommy1234
02-26-2012, 01:50 AM
HI
i'm sorry to say that it didn't help.
the problem is in the "Micorosoft PowerPoint 14.0 Object Library"
when i run my code There is a "error in hidden module" because i wrote my code in excel 2010 and some of the users have excel 2007.
is there an option to check which version is installed and according to that to check the right reference and un check the wrong one ?
thanks

Bob Phillips
02-26-2012, 03:32 AM
I can't see its the library if you have late bound it. Post it here, I have a 2007 machine that I can test it on. Supply the password as well, or unprotect it.

raji2678
02-26-2012, 08:45 PM
You can try to link it to another version of powerpoint dll

frank_m
02-27-2012, 01:45 AM
Hi Tommy,

Did you try opening it in Excel 2010, removing the powerpoint reference, since with late binding no powerpoint reference is needed, then save the workbook, and try opening in 2007 ?