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