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

Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

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

  1. #1
    Board Regular
    Join Date
    Nov 2002
    Location
    Denver, CO
    Posts
    110
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default 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 wksRTPT.Activate 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

  2. #2
    Board Regular Cbrine's Avatar
    Join Date
    Dec 2003
    Location
    Brampton
    Posts
    3,196
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default 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.

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com