Call compile error

Red over White

Board Regular
Joined
Jul 16, 2011
Messages
96
Office Version
  1. 2019
Platform
  1. MacOS
I have been using the Call function without too many problems, but am now getting an error message - Compile error: Expected Sub, Function or Property

The VBA code is

Rich (BB code):
Sub PrintRun()

Call Graph ' this one doesn't generate the error

Dim Config As Integer
Dim Ans As Integer
Config = vbYesNo + vbQuestion + vbDefaultButton1
Ans = MsgBox("If a QE answer Yes.", Config)

If Ans = vbYes Then

' Lines of code printing off various sheets, the code carrying on with

Application.DisplayAlerts = False

Dim Config1 As Integer
Dim Ans1 As Integer
Dim OpenTax as Boolean
Dim Tax as Workbook

Config1 = vbYesNo + vbQuestion + vbDefaultButton1
Ans1 = MsgBox("Tax calculation to print?", Config)
If Ans1 = vbYes Then

Call OpenTax ' this is where I get the error message

Sheets("Tax calculation").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1 ' Sheet 4

Workbooks.Close FileName:= _
        "/Users...2011.xlsm"

Application.DisplayAlerts = True

End If

If Ans = vbNo Then

' The code then carries on


The macro 'OpenTax' comes straight after 'PrintRun' in the same Module, and works as intended. I suspect the problem is around the If statements, or possibly the fact I have two "If Ans = vbYes Then" statements without a "vbNo" statement in between.

Any suggestions?
 
Last edited by a moderator:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,614
Office Version
  1. 365
Platform
  1. Windows
You have a variable with the same name as the procedure you are trying to call, which is why you get the error.
 

Red over White

Board Regular
Joined
Jul 16, 2011
Messages
96
Office Version
  1. 2019
Platform
  1. MacOS
Sorry, Fluff - I can't see it. Please point me to where I have duplicated the procedure.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,614
Office Version
  1. 365
Platform
  1. Windows
You haven't duplicated the procedure, you have created a Boolean variable with the same name. Look at the Dim statements just before you call OpenTax
 
Solution

Red over White

Board Regular
Joined
Jul 16, 2011
Messages
96
Office Version
  1. 2019
Platform
  1. MacOS
Now I see it - thanks. Here's to another good win on Saturday against Canada!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,614
Office Version
  1. 365
Platform
  1. Windows
Glad to help & thanks for the feedback.
 

Forum statistics

Threads
1,143,623
Messages
5,719,804
Members
422,245
Latest member
Kebad

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
Top