Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Name workbook

Posted on 2015-02-12
3
Medium Priority
?
76 Views
Last Modified: 2015-02-12
Hi,

How can I create a name for the new workbook using the below code. See attached file. See code


Sub Button1_Click()

  Dim Pivot_trans As Boolean
  Dim ResultSheet
 Dim PivotSheet
     With Sheets.Add
         Sheets("Pivot (3)").PivotTables(1).TableRange2.Copy .Range("A1")
         .Move
        Set PivotSheet = ActiveSheet
         With ActiveSheet.PivotTables(1)
             Pivot_trans = .ColumnGrand
             .ColumnGrand = True
             .Parent.Cells.SpecialCells(xlCellTypeLastCell).ShowDetail = True
            Set ResultSheet = ActiveSheet
             .ChangePivotCache ActiveWorkbook.PivotCaches.Create(xlDatabase, Selection, xlPivotTableVersion14)
             .ColumnGrand = Pivot_trans
             .Parent.Activate
         End With
            ResultSheet.Columns("H:K").Delete
             ResultSheet.Columns("D").Delete
           Application.DisplayAlerts = False
            PivotSheet.Delete
            Application.DisplayAlerts = True
     
     ResultSheet.Name = "hello"
 
     
     End With


 End Sub




------------------
Regards,

Marcell
Tracker-1-.xlsm
0
Comment
Question by:Marcell999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 2000 total points
ID: 40605473
You would have to save the resulting spreadsheet - you cannot name it otherwise.

Try

Sub Button1_Click()
 
  Dim Pivot_trans As Boolean
  Dim ResultSheet
Dim PivotSheet
Dim ResultWorkbook
     With Sheets.Add
         Sheets("Pivot (3)").PivotTables(1).TableRange2.Copy .Range("A1")
         .Move
        Set PivotSheet = ActiveSheet
       Set ResultWorkbook = ActiveWorkbook
         With ActiveSheet.PivotTables(1)
             Pivot_trans = .ColumnGrand
             .ColumnGrand = True
             .Parent.Cells.SpecialCells(xlCellTypeLastCell).ShowDetail = True
            Set ResultSheet = ActiveSheet
             .ChangePivotCache ActiveWorkbook.PivotCaches.Create(xlDatabase, Selection, xlPivotTableVersion14)
             .ColumnGrand = Pivot_trans
             .Parent.Activate
         End With
            ResultSheet.Columns("H:K").Delete
             ResultSheet.Columns("D").Delete
           Application.DisplayAlerts = False
            PivotSheet.Delete
            Application.DisplayAlerts = True
   
     ResultSheet.Name = "hello"
    ResultWorkbook.SaveAs "hellothere"
     End With
 
 
End Sub
 
 Alternatively, use ResultWorkbook.Save if you want to bring up a dialog box.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 40605476
You need to add a:
ThisWorkbook.SaveAs "your new filename and path"

Open in new window

line to the end.
0
 

Author Closing Comment

by:Marcell999
ID: 40605484
Thanks Phillip!!! You are great!!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question