OWC Pivot Printing through Excel ActiveX

D

Dip

Hi,
I am using a chunk of code on a OWC PivotTable Web Page which allows me
to Print directly from the page. What it does is just creates an Excel
Worksheet on the fly and copy the whole stuff(There is a push button
that executes the subroutine). As simple as that.

Now it's working fine with my own PC but not working while I am under
Corporate Domain. Upon pushing the button, at first a warning messagge
pops up saying "An ActiveX Control on this page might be unsafe to
interact with other parts of the page. Do you want to allow this
interaction?" After I press "yes" I am getting an page error at the
bottom saying "Permission Denied".
How to get around with this situation? Do I need tick some boxes at
Internet Explorer Seetings to allow me executing ActiveX Control?
Please help.
Thanks in Advance!
Dip

my code:


'-- PrintPivotInXL
'
' Copies the contents of an OWC PivotTable to Excel and
' then either prints it directly, or leaves the user
' in print preview mode, allowing the user to customize
' the print out and then print from within Excel.
'
Sub PrintPivotInXL()
Dim xlApp 'Ref to Excel application
Dim wkbk 'Ref to new workbook
Dim wksht 'Ref to worksheet
Dim pgsetup 'Ref to page setup object
Dim nCols 'Number of physical columns used by row
headings
Dim nRows 'Number of physical rows used by column
headings
Dim ptConstants
Dim PTSets
Dim PTField
Dim nr, nr2


'First copy the entire contents of the
'OWC PivotTable to the clipboard. By passing
'the ActiveView object, you are copying the entire view.
'Pass ptable.Selection to copy just the current selection

'Set Pivot Table Constants
Set ptConstants = ptable.Constants




'Assigning the Column values

For Each PTSets IN ptable.ActiveView.ColumnAxis.FieldSets
For Each PTField IN PTSets.Fields
IF PTField.IsIncluded Then
nr = nr + 1
End If
Next
Next

'Assigning the Titlebar Caption

IF ptable.ActiveView.TitleBar.Visible Then
nr = nr + 1
End If

IF ptable.ActiveView.FilterAxis.FieldSets.Count > 0 Then
nr = nr + 2
Else
nr = nr + 1
End If



For Each PTSets IN ptable.ActiveView.RowAxis.FieldSets
For Each PTField IN PTSets.Fields
IF PTField.IsIncluded Then
nr2 = nr2 + 1
End If
Next
Next

If(nr2 = 0) AND (ptable.ActiveView.RowAxis.Label.Visible) Then
nr2 = 1
End If


ptable.Copy ptable.ActiveView

'Create an instance of Excel (should work with
'Excel 97 or 2000 or maybe even 95)

Set xlApp = Nothing
Set xlApp = CreateObject("Excel.Application")

'Add a new workbook to the Excel instance
Set wkbk = xlApp.Workbooks.Add()

'Get a reference to the first worksheet in the new book
Set wksht = wkbk.Sheets(1)

'Paste the contents of the clipbard into that sheet
wksht.Paste wksht.Range("a1")

'Call AutoFit over the used range to make sure
'everything is visible.

wksht.UsedRange.Columns.AutoFit



wksht.Columns.ColumnWidth = 6
wksht.Rows.Font.Size = 5
wksht.Columns.Font.Size = 5


'Get the page setup object
Set pgsetup = wksht.PageSetup

pgsetup.PrintTitleRows = "$1:$" & nr
pgsetup.PrintTitleColumns = "$A:$" & Chr(Asc("A") + (nr2 - 1))


pgsetup.Orientation = 2 'xlLandscape

'Also tell it to print grid lines
pgsetup.PrintGridlines = True

'Set a default header/footer
'pgsetup.CenterHeader = ptable.ActiveView.TitleBar.Caption
'pgsetup.CenterFooter = "Page &P of &N"

'If fPreview Then
'put the current worksheet into print preview
xlApp.UserControl = True
xlApp.Visible = True
wksht.PrintPreview
'Else
'just kick off the print
'xlApp.UserControl = True
'xlApp.Visible = True
'xlApp.dialogs(8).Show
'End If 'fPreview

'close down our instance of Excel
'Note, to let the user interact with
'Excel instead, see the code in the above block

xlApp.Visible = False
xlApp.DisplayAlerts = False
xlApp.Quit

'release all our Excel objects
Set pgsetup = Nothing
Set wksht = Nothing
Set wkbk = Nothing
Set xlApp = Nothing


End Sub 'PrintPivotInXL()
 
D

Dan Ricker

The offending line of code is:
Set xlApp = CreateObject("Excel.Application")

Excel is Not Safe For Scripting. If Script in IE can
instantiate Excel and do anything it wants with the Excel
ObjectModel, then that client PC vulnerable to all sorts
of nasty attacks.

If clients/users get used to permitting unsafe ActiveX
controls, or set IE to allow unsafe activeX controls, then
one of the biggest security protective measures is
eliminated from IE.

If an IE instance can instantiate and run any ActiveX
control, the one might as well just run any Exce placed on
http://www.IHackYouEasily.com


The Office Web Compents Tool Pack provides a sample that
does basically the same thing as your code, but the
differences are:
1) The ToolPack uses a DLL that only performs one task,
the Printing/Print Preview via Excel.
2) Does not allow access to the object model of the Excel
instance started to do the printing/previewing.

The "PivotPrint.dll" provided in the toolpack is the best
way to go. If you need to create a different DLL to add
some functionality, then please ensure that it is
truely "Safe For Scripting" and "Safe For Initialization".
before marking the control as Safe and signing the
control.
__________________
-----
Thx
Dan

Quality is not just the absence of defects, but the
presence of value throughout the entire transaction.

-----Original Message-----

Hi,
I am using a chunk of code on a OWC PivotTable Web Page which allows me
to Print directly from the page. What it does is just creates an Excel
Worksheet on the fly and copy the whole stuff(There is a push button
that executes the subroutine). As simple as that.

Now it's working fine with my own PC but not working while I am under
Corporate Domain. Upon pushing the button, at first a warning messagge
pops up saying "An ActiveX Control on this page might be unsafe to
interact with other parts of the page. Do you want to allow this
interaction?" After I press "yes" I am getting an page error at the
bottom saying "Permission Denied".
How to get around with this situation? Do I need tick some boxes at
Internet Explorer Seetings to allow me executing ActiveX Control?
Please help.
Thanks in Advance!
Dip

my code:


'-- PrintPivotInXL
'
' Copies the contents of an OWC PivotTable to Excel and
' then either prints it directly, or leaves the user
' in print preview mode, allowing the user to customize
' the print out and then print from within Excel.
'
Sub PrintPivotInXL()
Dim xlApp 'Ref to Excel application
Dim wkbk 'Ref to new workbook
Dim wksht 'Ref to worksheet
Dim pgsetup 'Ref to page setup object
Dim nCols 'Number of physical columns used by row
headings
Dim nRows 'Number of physical rows used by column
headings
Dim ptConstants
Dim PTSets
Dim PTField
Dim nr, nr2


'First copy the entire contents of the
'OWC PivotTable to the clipboard. By passing
'the ActiveView object, you are copying the entire view.
'Pass ptable.Selection to copy just the current selection

'Set Pivot Table Constants
Set ptConstants = ptable.Constants




'Assigning the Column values

For Each PTSets IN ptable.ActiveView.ColumnAxis.FieldSets
For Each PTField IN PTSets.Fields
IF PTField.IsIncluded Then
nr = nr + 1
End If
Next
Next

'Assigning the Titlebar Caption

IF ptable.ActiveView.TitleBar.Visible Then
nr = nr + 1
End If

IF ptable.ActiveView.FilterAxis.FieldSets.Count > 0 Then
nr = nr + 2
Else
nr = nr + 1
End If



For Each PTSets IN ptable.ActiveView.RowAxis.FieldSets
For Each PTField IN PTSets.Fields
IF PTField.IsIncluded Then
nr2 = nr2 + 1
End If
Next
Next

If(nr2 = 0) AND
(ptable.ActiveView.RowAxis.Label.Visible) Then
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top