Solved

Excel VBA - Question about Syntax and the Language Structure

Posted on 2013-11-24
4
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 47

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 47

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

738 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