Call compile error

Red over White

Board Regular
Joined
Jul 16, 2011
Messages
123
Office Version
  1. 365
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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
You have a variable with the same name as the procedure you are trying to call, which is why you get the error.
 
Upvote 0
Sorry, Fluff - I can't see it. Please point me to where I have duplicated the procedure.
 
Upvote 0
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
 
Upvote 0
Solution
Now I see it - thanks. Here's to another good win on Saturday against Canada!
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,384
Members
448,956
Latest member
JPav

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