save but not save() -vba

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
How come excel would accept the first code but not the second one. I thought save is a function and if you call a function then you should use this syntax

ObjectName.FunctionName() <<if the function takes no argument >>

Sub myfirst()
Workbooks(1).Save
End Sub
++++++++++++++++++++
Sub myfirst()
Workbooks(1).Save ()
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Better question is why do you think it should accept the brackets? and no it is not a function.
 
Last edited:
Upvote 0
Thanks for your reply. I know you said it is not function but the Object browser is showing that Save has a green icon infront which mean it is function and when I click on it the Object browser says

Sub Save()
Member of Excel.Workbook

It is surprised me it says Sub not function but anyway still it has () as part of its syntax?

Thank you.
 
Upvote 0
Upvote 0
Thanks, I think I understand it now. Let say we have an object called ABC which has 2 functions, one is called foo1() which takes no argument and the second one is called foo2(int x) which takes one argument of type int. to call these functions in vba code, i can use the following

sub whatever()
ABC.foo1
ABC.foo2(100)
end

The idea is this, if the function does not take an argument then you can called it using function name without () but if the function takes an argument then you need () and pass the argument between (). Am I right?
 
Upvote 0
Yes for a Function but as Microsoft have stated .Save is not a Function, it is a Method.
 
Upvote 0
Thank you very much for helping me to understand. But I thought Method = Function. Sometime people call it method and sometime call it function. It is the same thing or I have been under impression they are the same thing, or different way to name same thing!! I guess I am wrong.
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,509
Members
449,089
Latest member
RandomExceller01

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