Assign Macro on Another Workbook

jalrs

Active Member
Joined
Apr 6, 2022
Messages
300
Office Version
  1. 365
Platform
  1. Windows
Hello guys, good morning

I'm trying to assign my macros to a sheet i created as a "Control Panel" on my masterWB.

i have this vba code on a template workbook, in order to copy the template with filtered information, without losing the template aftwerwards

VBA Code:
Sub primeiroTrimestre()

Dim path As String
Dim filename As String

path = "C:\Users\joafrodrigue\Desktop\prototipo\Difusao\"
filename = "ST_até31032022_Apoio SP"
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs filename:=path & filename & ".xlsx", FileFormat:=xlOpenXMLWorkbook
Application.DisplayAlerts = True

End Sub

i think the problem relies on ActiveWorkbook.SaveAs since when i try to assign the macro to the masterWB, it makes a copy of masterWB instead of the template one.

additionaly, i'd like to know how can i set current date as the filename, like "ST_atéDDMMYYYY_Apoio SP". Not sure if you find this question related to crossposting, but since i'm making a new thread with another question, felt like emphasizing it since I had no solution (here it is anyway Macro that saves a copy of a workbook into a specific location with a specific name)

any help is appreciated,

Thanks all!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
VBA Code:
Sub primeiroTrimestre()

dim wb1 as workbook
dim wb2 as workbook
Dim mypath As String
Dim myfilename As String

set wb1 = thisworkbook
Workbooks.Open Filename:=ThisWorkbook.Path & "\Controlo e Difusão\Templates\ST_TEMPLATE_Apoio SP.xlsx"
Set wb2 = Workbooks("ST_TEMPLATE_Apoio SP.xlsx")

mypath = "C:\Users\joafrodrigue\Desktop\prototipo\Difusao\"
myfilename = "ST_até31032022_Apoio SP"
Application.DisplayAlerts = False
wb2.Activate                                                         'activating workbook 2 helped solving the issue
wb2.SaveAs filename:=mypath & myfilename & ".xlsx", FileFormat:=xlOpenXMLWorkbook
wb2.close
Application.DisplayAlerts = True

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

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