Solved

Excel VBA - Question about Syntax and the Language Structure

Posted on 2013-11-24
4
303 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 46

Assisted Solution

by:Martin Liss
Martin Liss earned 250 total points
ID: 39673391
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
ID: 39673395
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
ID: 39674013
Thank you Martin and Dephault!

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

Thank you!
0
 
LVL 46

Expert Comment

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

Marty - MVP 2009 to 2013
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

828 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