Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Just to add to Micron's changes, it is easier to use individual variables to follow the object hierarchy (in your original version you were repeating the reference to the sheet inside the second With statement):


    Code:
    Dim xl As Object  'Excel application
    Dim xbk as Object 'Excel workbook
    Dim xls as Object 'Excel sheet
    
    
    Set xl = CreateObject("Excel.Application")
    Set xbk=xl.Workbooks.Open(myfile, , True)
    Set xls=xbk.Sheets("Statistics")
    
    With xls
          .Range("B1").Select
          .PivotTables("PivotTable1").PivotFields("ASSET").Orientation = xlHidden
          
          .Range("B2").Select
          .PivotTables("PivotTable1").PivotFields("CLUSTER").Orientation = xlHidden
    End With
    
    
    xl.DisplayAlerts = False
    myfilenew = Mid(myfile, 1, Len(myfile) - 5) & "-R1.xlsb"
    .SaveAs Filename:=myfilenew, FileFormat:=50
    .Close
    xl.DisplayAlerts = True
    
    
    xl.Quit 'close Excel
    
    
    Kill (myfile)
    Name myfilenew as myfile 'reset file name to original so your other code works without changes
    
    
    Set xls = Nothing
    Set xbk = Nothing
    Set xl = Nothing
    End Function
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  2. #17
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Post back if you need more help.
    I might be wrong, but some people here might not bother with your posts if you don't post code within code tags. Not everyone wants to manually type out your code from a picture in order to test or work with it.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Format Excel Cells to Number
    By DMT Dave in forum Access
    Replies: 1
    Last Post: 06-06-2019, 01:11 PM
  2. Import Excel cells into Access
    By NISMOJim in forum Macros
    Replies: 1
    Last Post: 04-19-2017, 02:24 AM
  3. Replies: 1
    Last Post: 01-09-2013, 04:11 PM
  4. Elo rating system - using VB to update cells
    By zeugma in forum Programming
    Replies: 1
    Last Post: 12-02-2010, 10:06 AM
  5. Excel exporting in single cells
    By Paolo29011982 in forum Import/Export Data
    Replies: 0
    Last Post: 07-29-2009, 04:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums