Solved

Excel VBA - Question about Syntax and the Language Structure

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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;…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

831 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