Combing normal macro code with recorded macro within a command button, is it possible!?

jaxisdex

New Member
Joined
May 26, 2015
Messages
35
I have created multiple command buttons that i need to make my life really easy. these were created by recording the macro and tweaking the results to what i needed. my final need is for it to automatically save as the value posted in a cell. the files have to be named a certain way so they can be uploaded into the company drives, which means spelling mistakes result in no-goes. So i had created a cell that updates the date that i need, and the unique name of the office each week. (There are over 60 of these, which is why ive been trying to automate them). I was able to create a save macro that works fine on its own, but it wont play with the recorded macro. is there a way i can include it? because it really makes my life super simple when everything is just one click! please and thank you for any and all advice! I am still fairly new to vba and am trying to learn how to do things but i am a slow man haha.

Basically im looking for a way to do a save as referencing a certain cell in my workbook on the CPS Links sheet cell A4.
Here is the code:

Private Sub CommandButton1_Click()

Sheets(Array("Sales Snapshot", "Cancellation Wheel", "Trending Cancellations", _
"Agent Cancels", "Agent Estimate Lost Profit", "Owner Estimate Lost Profit", _
"Trending Data", "CPS Links")).Copy
ActiveSheet.PivotTables("PivotTable5").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Trending Data!C1:C52", Version:=xlPivotTableVersion15)
Sheets("Cancellation Wheel").Select
ActiveSheet.PivotTables("PivotTable5").ChangePivotCache ( _
"Sales Snapshot!PivotTable5")
Sheets("Trending Cancellations").Select
ActiveSheet.PivotTables("PivotTable5").ChangePivotCache ( _
"Sales Snapshot!PivotTable5")
ActiveSheet.PivotTables("PivotTable6").PivotSelect "PeriodName[All]", _
xlLabelOnly, True
ActiveSheet.PivotTables("PivotTable6").ChangePivotCache ( _
"Sales Snapshot!PivotTable5")
Sheets("Agent Cancels").Select
ActiveSheet.PivotTables("PivotTable5").ChangePivotCache ( _
"Sales Snapshot!PivotTable5")
ActiveSheet.PivotTables("PivotTable1").ChangePivotCache ( _
"Sales Snapshot!PivotTable5")
Sheets("Agent Estimate Lost Profit").Select
ActiveSheet.PivotTables("PivotTable5").ChangePivotCache ( _
"Sales Snapshot!PivotTable5")
Sheets("Owner Estimate Lost Profit").Select
ActiveSheet.PivotTables("PivotTable5").ChangePivotCache ( _
"Sales Snapshot!PivotTable5")
Sheets("Trending Data").Select
ActiveSheet.Range("A:AZ").AutoFilter Field:=4, Criteria1:=Array( _
"Assurance International Inc", "Detroit Business Consulting Inc.", _
"Elite Advertising Inc.", "FBC", "Michigan Marketing Solutions, Inc.", _
"Modern Marketing Miami Inc", "Smith Advertising, Inc.", "The Plato Group Miami", _
"="), Operator:=xlFilterValues
Worksheets("Trending Data").Range("A2").Select
Worksheets("Trending Data").Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.EntireRow.Delete
Sheets(Array("Trending Data", "CPS Links")).Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Sales Snapshot").Select
ActiveWorkbook.RefreshAll
ActiveSheet.PivotTables("PivotTable5").PivotFields("OfficeName").CurrentPage = _
"(All)"
With ActiveSheet.PivotTables("PivotTable5").PivotFields("OfficeName")
.PivotItems("(blank)").Visible = False
End With
ActiveSheet.PivotTables("PivotTable5").PivotFields("OfficeName"). _
EnableMultiplePageItems = True

Dim FName As String
Dim FPath As String

Dim wbBook1 As Workbook

Set wbBook1 = ActiveWorkbook

FPath = "T:\Client Services\Cancellation Wheels\Weekly Data\Comcast\"
FName = wbBook1.Sheets("CPS Links").Range("A4").Text

End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
also i realize i never actually used .SaveAs filename:=Fpath & "\" & Fname at the end of my macro like i should have. I still can not get it to choose the new wb as the save as instead of the original. but i have also figured something out i think, and instead of adding the macro down there, i just added Call save instead. No idea if that helps or not
 
Upvote 0
Ok nevermind guys, i was able to figure it out. here is what it looks like at the end.

Private Sub CommandButton2_Click()
Sheets(Array("Sales Snapshot", "Cancellation Wheel", "Trending Cancellations", _
"Agent Cancels", "Agent Estimate Lost Profit", "Owner Estimate Lost Profit", _
"Trending Data", "CPS Links")).Copy

Call saveassintl

ActiveSheet.PivotTables("PivotTable5").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Trending Data!C1:C52", Version:=xlPivotTableVersion15)
Sheets("Cancellation Wheel").Select
ActiveSheet.PivotTables("PivotTable5").ChangePivotCache ( _
"Sales Snapshot!PivotTable5")
Sheets("Trending Cancellations").Select
ActiveSheet.PivotTables("PivotTable5").ChangePivotCache ( _
"Sales Snapshot!PivotTable5")
ActiveSheet.PivotTables("PivotTable6").PivotSelect "PeriodName[All]", _
xlLabelOnly, True
ActiveSheet.PivotTables("PivotTable6").ChangePivotCache ( _
"Sales Snapshot!PivotTable5")
Sheets("Agent Cancels").Select
ActiveSheet.PivotTables("PivotTable5").ChangePivotCache ( _
"Sales Snapshot!PivotTable5")
ActiveSheet.PivotTables("PivotTable1").ChangePivotCache ( _
"Sales Snapshot!PivotTable5")
Sheets("Agent Estimate Lost Profit").Select
ActiveSheet.PivotTables("PivotTable5").ChangePivotCache ( _
"Sales Snapshot!PivotTable5")
Sheets("Owner Estimate Lost Profit").Select
ActiveSheet.PivotTables("PivotTable5").ChangePivotCache ( _
"Sales Snapshot!PivotTable5")
Sheets("Trending Data").Select
ActiveSheet.Range("$A$1:$AZ$99999").AutoFilter Field:=4, Criteria1:=Array( _
"Alliance", "Detroit Business Consulting Inc.", _
"Elite Advertising Inc.", "FBC", "Michigan Marketing Solutions, Inc.", _
"Modern Marketing Miami Inc", "Smith Advertising, Inc.", "The Plato Group Miami", _
"="), Operator:=xlFilterValues
Worksheets("Trending Data").Range("A2").Select
Worksheets("Trending Data").Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.EntireRow.Delete
Sheets(Array("Trending Data", "CPS Links")).Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Sales Snapshot").Select
ActiveWorkbook.RefreshAll
ActiveSheet.PivotTables("PivotTable5").PivotFields("OfficeName").CurrentPage = _
"(All)"
With ActiveSheet.PivotTables("PivotTable5").PivotFields("OfficeName")
.PivotItems("(blank)").Visible = False
End With
ActiveSheet.PivotTables("PivotTable5").PivotFields("OfficeName"). _
EnableMultiplePageItems = True

End Sub

while the callassintl macro is as follow:

Sub saveassintl()
Dim FName As String
Dim FPath As String


Dim wbBook1 As Workbook


Set wbBook1 = ActiveWorkbook


FPath = "T:\Client Services\Cancellation Wheels\Weekly Data\Comcast\" <--- just add whatever you file path name is here
FName = wbBook1.Sheets("CPS Links").Range("A10").Text <---- choose the worksheet, with this code you have to choose from the currently active workbook. i just copied mine over and then made it hidden
wbBook1.SaveAs Filename:=FPath & "\" & FName
End Sub



I do have to go in and create a individual save macro for each office and then just change the cell value. but it does seem overall everything works perfectly. Sorry to have posted this,I had been stuck for 2 days but all of sudden had a eureka moment. i hope this helps someone else!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top