Solved

Excel VBA - Question about Syntax and the Language Structure

Posted on 2013-11-24
4
275 Views
Last Modified: 2013-11-25
To protect and unprotect a sheet you write:
Sheet2.Protect
Sheet2.unProtect

So, how come the same rule doesn't apply to displaying page breaks?  How come you have to write:
Sheet2.displayPageBreaks = True
Sheet2.displayPageBreaks = False

The following would make more sense given the grammar of the protect/unprotect statements.
Sheet2.displayPageBreaks
Sheet2.undisplayPageBreaks

I'm trying really hard to get a philosophical grip on the grammar of VBA and it's quite a chore.  I'm looking for some threads of logic as to when I need to use "=true" or when I need to type a subscript like  worksheets ("sheet1")

OR, do I just need to bite the bullet and memorize these language conjugations.
0
Comment
Question by:brothertruffle880
  • 2
4 Comments
 
LVL 45

Assisted Solution

by:Martin Liss
Martin Liss earned 250 total points
Comment Utility
It may not be easy to tell which is which but if it's a Property it's True/False but if it's a method you just invoke the method.
0
 
LVL 1

Accepted Solution

by:
Dephault earned 250 total points
Comment Utility
displayPageBreaks is a property that just has a True or False value

Property DisplayPageBreaks As Boolean
    Member of Excel.Worksheet


Unprotect & Protect are methods that accept other variables to action. But each of the two methods can be called without specifying the variables because they are all optional.(indicated with the [ ] )

If you are in the VBA window hit F2 for the Object browser. For example the worksheet.Protect is as below:

Sub Protect([Password], [DrawingObjects], [Contents], [Scenarios], [UserInterfaceOnly], [AllowFormattingCells], [AllowFormattingColumns], [AllowFormattingRows], [AllowInsertingColumns], [AllowInsertingRows], [AllowInsertingHyperlinks], [AllowDeletingColumns], [AllowDeletingRows], [AllowSorting], [AllowFiltering], [AllowUsingPivotTables])
    Member of Excel.Worksheet

Open in new window


VBA does have a fair bit of logic to it but you will need to 'get to know' various elements and know when to use them. That comes with time and experience.
0
 

Author Comment

by:brothertruffle880
Comment Utility
Thank you Martin and Dephault!

You explained it PERFECTLY.  Now I'm starting to see the logic behind the language!

Thank you!
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now