Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2005

Tip: Looking for answers? Try searching our database.

Basic Newbie Question: What's the ":=" operator for?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
termiflyer - 18 Aug 2005 20:11 GMT
I think the subject says it all.  For some reason I can't find it in
any references online.

Thanks
Charles Kenyon - 18 Aug 2005 20:19 GMT
It declares named parameters.
Signature

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

>I think the subject says it all.  For some reason I can't find it in
> any references online.
>
> Thanks
termiflyer - 19 Aug 2005 14:20 GMT
Could you give me an example of how and why I would use it?
Charles Kenyon - 19 Aug 2005 15:08 GMT
Sub AutoExecUnloadGlobal()
'   Written 1 April 2002 by Charles Kenyon
'   Automatically unloads this global template
'   Put in AutoExec procedure
'
   MsgBox prompt:="Sorry, " & ThisDocument.Name _
       & " cannot act as a global template.", _
       Title:=ThisDocument.Name & " improperly loaded", _
       Buttons:=vbExclamation
   AddIns(ThisDocument.FullName).Installed = False
End Sub

   ThisDocument.SaveAs FileName:=sDocFullPathNew, FileFormat:= _
       wdFormatTemplate, LockComments:=False, Password:="",
AddToRecentFiles:= _
       False, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
       False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
       SaveAsAOCELetter:=False

   MsgBox _
       prompt:="This template has been saved in the directory:" _
           & vbCrLf & Word.Options.DefaultFilePath(wdUserTemplatesPath) _
           & vbCrLf & "as " & ThisDocument.Name & ".", _
       Title:="Template save completed!"

Sub TemplatesPathIsMacro()
'
' TemplatesPathIsMacro Macro
' Macro written 3 December 2001 by Charles Kyle Kenyon
'
   Dim sUserTemplatesLocation As String
   Dim sWorkgroupTemplatesLocation As String
   Dim sStartUpTemplatesLocation As String
'
   sUserTemplatesLocation = Options.DefaultFilePath(wdUserTemplatesPath) &
"\"
   sWorkgroupTemplatesLocation =
Options.DefaultFilePath(wdWorkgroupTemplatesPath) & "\"
   sStartUpTemplatesLocation = Options.DefaultFilePath(wdStartupPath) & "\"
'
   MsgBox prompt:="The user templates are in:" & vbCrLf _
       & sUserTemplatesLocation & vbCrLf & vbCrLf _
       & "The Workgroup Templates are in:" & vbCrLf _
       & sWorkgroupTemplatesLocation & vbCrLf & vbCrLf _
       & "The Startup (Add-In) Templates are in:" & vbCrLf _
       & sStartUpTemplatesLocation, _
       Title:="Templates location settings"
End Sub

Private Sub LockUnlockFormToggleV()
   '   Toggle macro to protect / unprotect form
   '   Written by Charles Kenyon
   Dim oDoc As Document
   Set oDoc = ActiveDocument
   If oDoc.ProtectionType <> wdNoProtection Then
       oDoc.Unprotect
   Else
       If oDoc.ProtectionType = wdNoProtection Then
           oDoc.Protect _
               Type:=wdAllowOnlyFormFields, _
               NoReset:=True
       End If
   End If
End Sub

Private Sub DetachDoc()
'   Written by Charles Kyle Kenyon on December 1, 2003
'
   Dim sTemplatesPath As String
   sTemplatesPath =
Application.Options.DefaultFilePath(wdUserTemplatesPath)
   With ActiveDocument
       .UpdateStylesOnOpen = False
       .AttachedTemplate = _
           sTemplatesPath & "\Normal.dot"
   End With
End Sub

Above are some code snippets using named parameters. Otherwise, you list
your parameters, separated by commas, in order. This makes code (somewhat)
easier to read.
Signature

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

> Could you give me an example of how and why I would use it?
termiflyer - 19 Aug 2005 21:25 GMT
See if I interpret this correctly.  These are the same:

oDoc.Protect _
               Type:=wdAllowOnlyFormFields, _
               NoReset:=True

and

oDoc.Protect(wdAllowOnlyFormFields, True)

Using named parameters only makes the code more readable, nothing else?
Jay Freedman - 19 Aug 2005 21:56 GMT
> See if I interpret this correctly.  These are the same:
>
[quoted text clipped - 8 lines]
> Using named parameters only makes the code more readable, nothing
> else?

Not quite... there's one more wrinkle in there.

If you omit the parameter names, then you must have at least a comma for
every possible parameter up to the one just before the last value you
supply, and you have to put the values in the order specified by the syntax
diagram in the help. If you use the names, then you can include only the
ones you're actually giving values for, in any order.

As an example, take the MsgBox function. The full syntax is

 MsgBox(prompt[, buttons] [, title] [, helpfile, context])

Let's say I want to supply values for the prompt and title parameters, and
accept the defaults for buttons, helpfile, and context. If I supply
parameters by position (that is, without the names), then I have to write

  MsgBox("Hello",  , "My Title")

Notice the empty second comma, which serves as a placeholder for the buttons
parameter.

If I use the names, then I can put in just the prompt and title without
worrying about any of the default values, and I can even supply the values
out of order:

  MsgBox(title:="My Title", prompt:="Hello")

One other thing: Use the parentheses around the parameters only if you're
going to use the return value of the function; if you're using it as a
statement, omit the parentheses. See
http://word.mvps.org/FAQs/MacrosVBA/BracketsWithArgmnts.htm for explanation.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.