Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default universal code

I used the record macro so I can programatically re-run getting external data
into a pivot table after clearing and deleting all the cells. The macro
recorded explicitly to the workbook I was working in while recording. I'd
like help with making my code more universal. How should I modify the
following code to allow it to run on different workbooks?

..CreatePivotTable TableDestination:=" ' [Workbook Name.xls] Query Name ' !
R5C1", _
TableName:="PivotTable5", DefaultVersion:=xlPivotTableVersion10

and

ActiveWindow.Visible = False
Windows("Workbook Name.xls").Activate
Range ("A2").Select

Thanks,
Lou Sanderson
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default universal code

up front

Set oWb = workbooks("Workbook Name.xls")


and then

..CreatePivotTable TableDestination:=" ' [" oWb.Name & "] Query Name ' !
R5C1", _
TableName:="PivotTable5", DefaultVersion:=xlPivotTableVersion10

and

ActiveWindow.Visible = False
Windows(oWb.Name).Activate
Range ("A2").Select



--

HTH

RP
(remove nothere from the email address if mailing direct)


"lou sanderson" wrote in message
...
I used the record macro so I can programatically re-run getting external

data
into a pivot table after clearing and deleting all the cells. The macro
recorded explicitly to the workbook I was working in while recording. I'd
like help with making my code more universal. How should I modify the
following code to allow it to run on different workbooks?

.CreatePivotTable TableDestination:=" ' [Workbook Name.xls] Query Name ' !
R5C1", _
TableName:="PivotTable5", DefaultVersion:=xlPivotTableVersion10

and

ActiveWindow.Visible = False
Windows("Workbook Name.xls").Activate
Range ("A2").Select

Thanks,
Lou Sanderson



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default universal code

..CreatePivotTable

alone means nothing, there's probably a "with" few lines before,
refering to which object we add a pivot table

then, you can change it, example...

With ActiveWorkbook.PivotCaches.Add(SourceType:=xlExter nal)
' stuff
.CreatePivotTable
'stuff
end with


this ActiveWorkbook means... the active workbook, so not one book but
anyone one (the active one)...


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
Universal formulas for any given row lamontd7 New Users to Excel 3 August 1st 05 02:55 PM
Universal procedure for changes Matt Jensen Excel Programming 5 December 29th 04 03:48 PM
Universal Macro Sam Thurston Excel Programming 2 February 21st 04 12:28 AM
Need new idea for universal path Dan Merchant Excel Programming 0 August 1st 03 01:50 PM
Need new idea for universal path Steve Smallman Excel Programming 0 August 1st 03 09:19 AM


All times are GMT +1. The time now is 03:08 AM.

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"