Excel - VBS script

Posted on 2001-08-13
Last Modified: 2008-03-04
From my VBS script, I want to protect some columns and hide another column.  And of course I want to leave one unprotected.  What is the syntax for the hidden?

Question by:cmarshall
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
  • 3
LVL 16

Expert Comment

ID: 6381543
'I suppose you have a valid variable for sheet object already.
' This switch visible and hide alternatively
mySheet.Visible = Not (mySheet.Visible)

Expert Comment

ID: 6381564
For hiding columns use syntax similar to:

ActiveWorkbook.ActiveSheet.Range("D1").EntireColumn.Hidden = True

ActiveWorkbook.ActiveSheet.Range("A1:B1").EntireColumn.locked = True

This will protect columns A and B and leave C unprotected.  You can give the protect method a password string, but you must protect the sheet for the locked property to have any meaning and work.

Hope this helps,


Author Comment

ID: 6381578
Thank you eeevans....  What resource would you recommend for the future?

Expert Comment

ID: 6381662
You can ask these type of questions in the Microsoft newsgroups if you have access to newsgroups.  If not you they have a web interface for them on msdn online at:

and click on Office Solutions Development and then Excel and then Programming or in your news reader open microsoft.public.excel.programming.

Also you can always turn on the macro recorder by selecting Tools->Macros->Record New Macro in the toolbar and then do what you want to manually and then look at the code that was recorded for what you did manually.  It will help a lot with syntax etc.

Hope that helps,


Accepted Solution

eeevans earned 100 total points
ID: 6381825
And there's always the fine folks here at EE.


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month4 days, 3 hours left to enroll

630 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