Excel Why do I have to activate my worksheet for this to work? from Mr Excel


 FAQFAQ
   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   StatisticsStatistics 
 RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Online StoreOnline Store

MrExcel Message Board Forum Index -> Excel Questions

Why do I have to activate my worksheet for this to work?
Post new topic   Reply to topic
Last Thread | Next Thread  >   Printable version
  Author    Thread

Amileaux
Board Regular


Joined: 04 Nov 2002
Posts: 90
Location: Denver, CO
Flag: Usa

Status: Offline

 Reply with quote  

Why do I have to activate my worksheet for this to work?

Below is a portion of VB that I use in Access to populate an excel worksheet.
Everything works just fine until: wksRTPT.Range("A1").Select. I continually errored out (error 1004: select method of range class failed) UNTIL I added the line [size=18]wksRTPT.Activate[/size] before it. Whey would the lines of code before work and this one little line not work until I activate the worksheet explicity? To update the pivot tables I had to implicitly be on that worksheet. I'm confused. Marie

Dim wkbTemplate As Excel.Workbook
Dim wksRTPT As Excel.Worksheet
Set wkbTemplate = GetObject(strFilePath & "DailyFlash.xlt")
Set wksRTPT = wkbTemplate.Worksheets("RTPT")

'Refresh Pivot Tables
For i = 1 To wksRTPT.PivotTables.Count
wksRTPT.PivotTables(i).RefreshTable
Next
wksRTPT.Cells.EntireColumn.AutoFit
wksRTPT.Columns("A:A").ColumnWidth = 15.57
wksRTPT.Activate
wksRTPT.Range("A1").Select

Post Thu Jan 08, 2004 7:46 pm 
 View user's profile Send private message

Cbrine
Board Master


Joined: 02 Dec 2003
Posts: 589

Flag: Canada

Status: Offline

 Reply with quote  

Re: Why do I have to activate my worksheet for this to work?

I'm not sure of the reason why, but when I was build some MSAccess reports using the Excel object, I found that some of the syntax I use in the Excel Editor didn't work using the Excel Object. I espcially had trouble with my references. Don't remember the exact problems, it was a while ago.
_________________
Heisenberg may have slept here.

Post Thu Jan 08, 2004 7:49 pm 
 View user's profile Send private message
  Display posts from previous:      

MrExcel Message Board Forum Index -> Excel Questions


Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 1 of 1



Add To Favorites

 


Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB: 2.0.4 © 2001 phpBB Group

Need help posting your first question? Read how to post

Need extra help ? Couldn't get the answer you needed ? Get a free quote from our Consulting Team

Download Colo's HTML Maker utility for displaying your Excel Worksheet on the board.

Download VB HTML Maker to post your code on the board


Check out our new index to 485 Excel Articles.


Return to MrExcel Consulting

All contents Copyright 1998-2004 by MrExcel.com
If you believe information posted here is from your copyrighted source, notify us per the Terms of Use
Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.