Amalgamating 2 macros gives Compiler error.

Kayslover

Board Regular
Joined
Sep 22, 2020
Messages
168
Office Version
  1. 2013
Platform
  1. Windows
I have 2 macros that I am trying to amalgamate.

Macro1 uses an InputBox to get data from the User and stores the answer in a specific sheet in the Template that is opened to run the macro. The code for macro 1 is:-

VBA Code:
Dim myYear As Integer
myYear = InputBox("Please enter the year (Format YYYY) that you want to create monthly Sheets for", "Enter Year")
Sheets("Formula").Select
Range("R2").Value = myYear
ActiveWorkbook.Save

Macro 2 starts off with the statements:-

VBA Code:
Dim ws As Worksheet
fPath = ThisWorkbook.Path & "\"

It then proceeds to use the following command:-

VBA Code:
ActiveWorkbook.SaveAs Filename:=fPath & "01 January.xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled

to save 12 workbooks with the names 01 January, 02 February, etc etc etc.

I am attempt to amalgamate the 2 macros, I get the error “Compiler error: Variable not found” against the line fPath = ThisWorkbook.Path & "\".

When I run the macros individually or call macro 2 from macro 1, then no problems are encountered.

Any assistance offered would be gratefully received.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi,
Declare the missing variable & see if resolves issue

Rich (BB code):
Dim ws As Worksheet
Dim fPath As String

fPath = ThisWorkbook.Path & "\"

Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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