Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Pivot Table using VB Script

Hi
I am trying to automate MS office on the client side. I
wish to create a pivot table on my local machine using VB
Script. I have the data in an excel file stored on my
hard drive with the data as shown below (Stored as
C:\MyExcelVB.xls). I have a simple HTML page with VB
script on it. The VB Script uses a method called
PivotTableWizard. The first time I executed the code, it
ran successfully. Thereafter every time I executed the
code (after recreating the excel file), it showed an
error saying "PivotTableWizard method of WorkSheet Class
Failed". I also tried to execute the code on my
neighbour's PC... but it showed the same.
The code is provided below. Any pointers or help in this
matter... Please help me.

CODE:
<HTML
<BODY
<INPUT id=button1 name=button1 type=button value=Button

<SCRIPT LANGUAGE="VBScript"
sub button1_onclick()
Dim xlObj

'Set xlObj = GetObject(, "Excel.Application")
'Set xlObj = new ActiveXObject("Excel.Application")
Set xlObj = createobject("Excel.Application")
xlObj.Visible = True
xlObj.Workbooks.Open "C:\myExcelVB.xls"
With xlObj
.Range("A1").Select
.ActiveSheet.PivotTableWizard
SourceType=xlDatabase,_
SourceData="Sheet1!R1C1:R5C3",TableDestination="", _
TableName="PivotTable1"
.ActiveSheet.PivotTables("PivotTable1").AddFields _
RowFields="Office", ColumnFields="Region"
.ActiveSheet.PivotTables("PivotTable1"). _
PivotFields("Sales").Orientation = xlDataField
End With
xlObj.ActiveSheet.UsedRange.Select
Documents.Add
Set xlObj = Nothing
End Sub

</SCRIPT

</BODY
</HTML


EXCEL DATA: (C:\MyExcelVB.xls)


Region Office Sales
North Alpha 100
East Beta 120
West Alpha 130
North Beta 100
East Beta 140
West Alpha 110



Thank you,
Regards,
Sovon

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Pivot Table using VB Script

I am not 100% certain, but I believe that the Docments.Add should be
associated with the xlObj... Otherwise, vbs probably doesn't know what
to do with it. Again though, I could be mistaken.


On Mon, 28 Jul 2003 03:40:25 -0700, "Sovon Chatterjee"
wrote:

Hi
I am trying to automate MS office on the client side. I
wish to create a pivot table on my local machine using VB
Script. I have the data in an excel file stored on my
hard drive with the data as shown below (Stored as
C:\MyExcelVB.xls). I have a simple HTML page with VB
script on it. The VB Script uses a method called
PivotTableWizard. The first time I executed the code, it
ran successfully. Thereafter every time I executed the
code (after recreating the excel file), it showed an
error saying "PivotTableWizard method of WorkSheet Class
Failed". I also tried to execute the code on my
neighbour's PC... but it showed the same.
The code is provided below. Any pointers or help in this
matter... Please help me.

CODE:
<HTML
<BODY
<INPUT id=button1 name=button1 type=button value=Button

<SCRIPT LANGUAGE="VBScript"
sub button1_onclick()
Dim xlObj

'Set xlObj = GetObject(, "Excel.Application")
'Set xlObj = new ActiveXObject("Excel.Application")
Set xlObj = createobject("Excel.Application")
xlObj.Visible = True
xlObj.Workbooks.Open "C:\myExcelVB.xls"
With xlObj
.Range("A1").Select
.ActiveSheet.PivotTableWizard
SourceType=xlDatabase,_
SourceData="Sheet1!R1C1:R5C3",TableDestination="", _
TableName="PivotTable1"
.ActiveSheet.PivotTables("PivotTable1").AddFields _
RowFields="Office", ColumnFields="Region"
.ActiveSheet.PivotTables("PivotTable1"). _
PivotFields("Sales").Orientation = xlDataField
End With
xlObj.ActiveSheet.UsedRange.Select
Documents.Add
Set xlObj = Nothing
End Sub

</SCRIPT

</BODY
</HTML


EXCEL DATA: (C:\MyExcelVB.xls)


Region Office Sales
North Alpha 100
East Beta 120
West Alpha 130
North Beta 100
East Beta 140
West Alpha 110



Thank you,
Regards,
Sovon


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
how to create pivot table from existing pivot table in excel 2007 Udayraj Dhulekar Excel Discussion (Misc queries) 2 July 8th 13 08:22 PM
Print Pivot Table headers on pages with Pivot Table tsgoose Excel Worksheet Functions 0 December 9th 08 08:14 PM
Filter lines with Pivot table and non pivot table columns Grover Charts and Charting in Excel 4 September 28th 07 03:16 AM
Filter lines containing pivot table and non pivot table data Grover Excel Worksheet Functions 0 September 24th 07 07:20 PM
How do I create a pivot table if the pivot table icon or menu ite. Lynn@WS Charts and Charting in Excel 1 December 16th 04 02:36 AM


All times are GMT +1. The time now is 07:22 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"