~ AnyFrontPage Bytes News:
CHANGE OF PACE
Wow! Has it been a year, already? This issue is a special issue indeed!
The official kick-off of our Vol II issues. Surprised? It has been a
surprising and cutting-edge year. Our small community has seen the first and
been the first in many areas. Your editors work hard on your behalf to bring
new resources, tips and articles to the ezine for your enjoyment and we have
lots of upcoming projects to that end.
We've decided that we can best meet those future goals by issuing your
Bytes monthly, rather than bi-weekly. So beginning with this new, Volume II,
Issue 1, we are doing just that. Publish date will be the second Thursday of
the month. We are excited about future plans and look forward to another
year of the latest and greatest in the FrontPage experience. We promise to
bring you all that continuing FrontPage education and to make it Fun!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HAPPY BIRTHDAY
Let us wish a very happy October birthday to the following AFP Bytes
members:
Tom Flynn
Dan Fiorito
Dave (red_tyke@...)
Donna Ball
Stephanie Gray
Tjarda Leegsma
K Cooper
WE ARE ONE!!
We are thrilled to announce that as it is the birthday of AnyFrontPage
Bytes, Everyone can be a winner! We are throwing a cyber birthday bash, and
inviting all of our AFP Bytes members. This is a very special thank you to
all - contributing authors, subscribers, everyone who has helped us make
this year such a success. Everyone that comes to our party is a winner as
well as the above birthday people! YES! Everyone who attends our birthday
party will get a surprise present!
WHERE: AFP Chat room
[ out of date link - removed ]
WHEN: Friday, October 11th, 2002 4pm - 6pm EST! This is Eastern Standard
Time! For a breakdown of what that is in your time zone see:
http://anyfrontpage.com
DRESS: Get down and boogie attire; hats, party favors and snacks will be
provided
R.S.V.P by email to -
editors@anyfrontpage.com
For those who would like to create a birthday card for AnyFrontPage
Bytes, please see [ out of date link - removed ]
for more info. We will decorate the
chat room with them and there will be a grand prize for our favorite! (Hint:
signing your card with your URL gets a link back to your site<G>)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PARTY TIME!!! - YOUR INVITED
Not enough partying for FrontPage Crafters? Of COURSE not (smile) To make
it back-to-back or even non-stop we are celebrating again on the very next
day. This party is in honor of our very own editor, Tiffany K. Edmonds, MS
MVP - FrontPage. You read that right - Microsoft has recognized Tiffany as
an outstanding contributor in her technical community. We are so proud of
her. She has been asked to join their team of MVPs to help support and
assist … Well, this will certainly not be new to Tiffany, will it?
Congratulations, Tiffany, you certainly deserve this!
WHERE: AFP Chat room
http://www.anyfrontpage.com/chat/
WHEN: Saturday, October 12th, 2002 11am - 1pm EST! This is Eastern
Standard Time! For a breakdown of what that is in your time zone see:
http://www.anyfrontpage.com
~ SPECIAL NOTE: Everyone who attends Tiffany's party will receive a
present from AnyFrontPage! This will be a special gift and a different gift
from the Birthday Party so be sure to attend each.
THANK YOU to all those that promoted the parties for us.
[ out of date link - removed ]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
↑ Top
|
MAIN ARTICLE
EXTENDING FRONTPAGE WITH MACROS
PART I
By Alex Tushinsky
http://LTMOD.com
With the release of FrontPage 2000, Microsoft
implemented one of FrontPage's strongest
features, yet few of us have seen or even heard
of this. Yes, folks, I'm talking macros!
Whatever the reason, macros have received a
fairly bad reputation over the years - perhaps
due to how we remember these things - which
first appeared in Lotus 123 for DOS. Back then,
professional programmers got nosebleeds while
creating and maintaining these linear beasts.
Coding wasn't for the squeamish. However,
today's macro is very easy to work with, yet
hundreds of times more powerful. Consider the
tedious chore of copying and pasting content
from one template to another. For a small 10
page site, this is easy, but what if the site has
over 700 pages? By spending a couple of hours
building the right macro, you can convert all 700
pages in less than an hour instead of weeks!
In this tutorial we'll look at FrontPage's macro
environment, learn a few basic rules, and create
a simple macro to simplify a common chore.
Lets begin with the definition for the word macro.
After all, what is it, really? Well, a macro is a
recorded or coded sequence of steps which are
used to perform a specific task. In Microsoft
products, this is accomplished through a
powerful language known as Visual Basic for
Applications or VBA for short. If you're
shuddering from the thought of coding, fear not.
Microsoft realized years ago, that any language
they use to produce macros must be easy to
work with, since the products that use macros
are not necessarily in the hands of professional
developers, but regular users. VBA was the
perfect choice since it removes a lot of
programming nightmares, while remaining quite
powerful. Lets look at a few basics of VBA:
1 - VBA is not case-sensitive. Most
programming languages like JavaScript, C++,
etc require you to enter code in a specific
case-sensitive state, but not VBA. Upper-case,
lower-case, still works!
2 - Object-oriented - An object is a building
block of an application. In essence, FrontPage
itself is comprised of a number of objects, all of
which are at our control. We don't have to worry
about how they were programmed or how they
work - we can simply use them to achieve our
results. All we have to know is what each one
does! Objects have Properties (things that we
can set or change depending on what we want)
and Methods (actions that the object performs).
If you consider a car - a car is an object. Things
like make, model, number of doors, size of
engine, color would be its properties, while
driving forward, and stopping would be its
methods. In FrontPage VBA, an object could
be a web page, or an HTML tag. For example
for a <P> tag (paragraph tag), you could have
properties like align (left, right, center, justify),
class, and style. A method for setting these
properties (setAttribute) would also be included,
so we could do this programmatically.
3 - Developing complex forms is easy. You use
drag-and-drop objects to create forms.
4 - Learning VBA leads to other great things.
Microsoft Visual Basic, ASP, and VBA all use a
common language. If you learn one, you know
them all. As a result, you can build Windows
Apps, Macros and code the web, all with one
language.
To make things easier for new users, Microsoft
has continuously updated and released the
Microsoft FrontPage SDK (Software Developers
Kit) which includes everything you need to know
to be a FrontPage VBA guru. This kit can be
downloaded from the Microsoft Developer's
Network (MSDN) at the following URL:
http://anyfrontpage.com/rd/sdk.htm
The kit is in compiled HTML form, and allows
you to quickly search for particular topics of
interest. While I doubt anyone has the time or
the patience to read through all of it, I would
study certain sections, at least ones you think
you will be working with.
The next step is to take a closer look at the
environment we'll be working with. In
FrontPage, all macros have to be typed in
(unlike Excel or Word where they can simply be
recorded) and for that we need a Visual Basic
editor. In FrontPage, click on the Tools menu,
then select Macros, then choose Visual Basic
Editor. A new screen will appear, with several
panels that require some investigation. By
default, in the upper left hand corner of the
screen, you'll see "Projects" panel. In this
panel, you'll find a Module folder, with a Module
1 file in it. While you can add as many modules
as necessary, the one available will do the trick
quite nicely. You can actually record thousands
of macros into this one mod. The Projects
panel may hold other things as well, such as
user forms, but that we'll look at in a different
tutorial.
Below the Projects panel is the Properties
panel. Properties are pieces of information that
you can change for various objects. For now,
we can leave this alone as well.
Double-click on the Module folder in the Projects
panel. Double-click on the Module 1 file. A code
window will pop-up. This is where we type in our
macros. Before we can create a macro, we
need to name it. There are several types of
macros we can create - Functions and
Sub-Routines. A Sub-routine is a set of VBA
statements that are executed in sequence. A
function also executes a set of statements, but
returns a value as well. Today, we'll be building
a sub-routine that changes a web page's
margins for IE and Netscape. Make sure that
the two drop-downs at the top of the window
show "(General)" and "(Declarations)"
In the Code window, type in:
Sub ChangeBodyMargins and hit enter.
The editor will respond by creating a new Sub
called ChangeBodyMargins and create a start
and end for it. We can now add all of the code
we want between Sub ChangeBodyMargins()
and End Sub.
Our goal is to create a macro that adds the
following 4 attributes to the HTML BODY tag.
We need LEFTMARGIN = "0" and TOPMARGIN
= "0" for Internet Explorer, and MARGINHEIGHT
= "0" and MARGINWIDTH = "0" for Netscape
Navigator. This will setup our page to have no
margins, so whatever content we add to it,
starts at the edge of the page. Here's basically
what our body tag should look like:
<body leftmargin="0" topmargin="0"
marginheight="0" marginwidth="0">
A quick search on "HTML BODY" in the SDK
will yield 5 or 6 results, the last of which, titled
"Understanding the differences between the
FPHTML objects and the IHTML objects" tells
us exactly what we want to know! If you look at
the last example on the page, you'll see a bit of
code that sets the NOWRAP attribute of the
body tag to true. In our case, we'll be setting
LEFTMARGIN, TOPMARGIN, MARGINHEIGHT
and MARGINWIDTH, but the concept's the
same. So, we can safely take the first 2 lines of
code from that example:
Dim fpBody As FPHTMLBody
Set fpBody = ActiveDocument.body
Well, all we have to do now is find out how to
set our 4 attributes and we're home free. Before
that though, let's review what the code above
does. The first line which starts with DIM
defines a variable we called fpBody as the
FPHTMLBody object. What that means is that
we can call fpBody and it will contain all aspects
of the BODY HTML tag. This means that
fpBody now understands all of BODY's
attributes and actions. We have created an
instance of FPHTMLBody object for our own use
and called it fpBody. More than likely, there will
be a property for LEFTMARGIN and
TOPMARGIN, and probably an action of some
sorts that defines custom attributes.
Type in fpBody on a blank line, then type in a
period (.). A drop-down menu appears
identifying properties and methods. If you look
through this rather long list of BODY features,
you'll see one called set Attribute. Since setting
attributes is exactly what we intend to do, we'll
give this one a shot. So our line should now
read: fpBody.setAttribute
Note that VB helps you out with balloon help
and identifies the parameters required to
complete the setAttribute action. It states that
strAttributeName and AttributeValue are
parameters that can be passed to the action.
Str stands for string or text, which means that
whatever you type here, should be in
double-quotes. The AttributeValue doesn't have
str in front of it, so can potentially take a
number. So to complete our statement, we'll
type "LEFTMARGIN", 0 so our statement now
looks like this:
fpBody.setAttribute "topmargin", 0
Lets add the others:
fpBody.setAttribute "leftmargin", 0
fpBody.setAttribute "marginheight", 0
fpBody.setAttribute "marginwidth", 0
Our finished code should look like this:
Sub ChangeBodyMargins()
Dim fpBody As FPHTMLBody
Set fpBody = ActiveDocument.body
fpBody.setAttribute "topmargin", 0
fpBody.setAttribute "leftmargin", 0
fpBody.setAttribute "marginheight", 0
fpBody.setAttribute "marginwidth", 0
fpBody.setAttribute
End Sub
To see if any of this works, click the Play button
in the toolbar (the triangle) or press F5. If all
goes well, your page in FP should now have the
correct BODY attributes. Save your macro and
return to FrontPage to check. If VB gave you an
error of some sorts, then check your code.
There may be a mistake somewhere.
Back in FrontPage, we'll want to assign a button
to this macro, and stick it somewhere in our
toolbar. For that we can use FrontPage's
Customize option (under Tools Menu). Scroll
down in the list of categories until you see
Macro. Select it, and you'll see a Happy Face
icon pop-up on the right side of the screen.
Click on the happy face and drag it up towards
one of your toolbars. Insert it into a toolbar.
Right-click over the button and select Assign
Macro. A new window will pop-up that allows
you to select a procedure to run when the button
is clicked. Our ChangeBodyMargins macro will
appear in this list. Click on it. Now every time
you open a page and want to set the margins to
zero, simply click the happy face and you're all
set.
Well, I hope you enjoyed this brief tour of VBA.
Today you got a basic familiarity with the VB
Editor, and the very basics of code. If you're
stuck somewhere, feel free to drop me a line at
alext@ltmod.com. In the next tutorial, we'll
look at more complex code, examine functions,
objects, properties and methods in more detail,
and work on something that requires user input.
ABOUT THE AUTHOR
******************************
Alex Tushinsky is the chief operating officer of
LTMOD.COM and developer of PageTools, and
Media Manager add-ons for Microsoft®
FrontPage® 2002 and Microsoft® FrontPage®
2000. Alex's extensive programming and web
site design experience includes work with
international, national, and local corporations,
small businesses and non-profit organizations.
His teaching resume includes courses for
groups of 2-200 and instruction in the areas of
Web Design & Development, Programming,
Graphics Development, and other web related
technologies.
http://ltmod.com
******************************
~~~~~~~~++++SPONSOR AD++++~~~~~~~
NetStudio™
http://anyfrontpage.com/rd/ns.htm
Why struggle with Photoshop® when NetStudio™ does all you need in 10
minutes? For a limited time, save $10
~~~~~~~++++SPONSOR AD++++~~~~~~~~
↑ Top
|