This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > FrontPage Programming > December 2003 > Using VBA to automate shared border updating
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Using VBA to automate shared border updating
|
|
| Jim Trick 2003-12-27, 10:28 pm |
| I'm attempting to use VBA to provide my users with a form
that will allow them to "fill in the blanks" each of which
is a textbox representing unique information (unique to
the web they are administering). Once the form
is "submitted", this unique information would be stored in
a file, then be written to the required positions in to
the top, left and bottom shared border files for the web
concerned. The idea is to remove the requirement for users
to directly edit border files.
I'm at the point where the form information can be
successfully written to a text file which resides within
the web structure and now need to read each line from the
text file back into the successive text boxes on the form.
(The reason that this is required is to make editing
changes easy by populating the form with current saved
values once the form contents have been previously created
and saved). My thought was that I could do this using an
array, but I have had no luck. I want to populate each
textbox in the form with the saved values before
displaying it.
Any advice would be appreciated, including pointers to any
websites that deal extensively with VBA issues. I've
searched for but not found any helpful sites.
Thanks,
Jim
| |
| MD WebsUnlimited.com 2003-12-28, 6:28 am |
| Hi Jim,
I'm not sure I fully follow the application here but what I believe you wish
to do is use a VBA form to collect information then save it to a file and to
the shared border files at specific locations. I don't have this specific
code and the process is not overly trivial. I may have some time this
morning and write this up and provide it to you.
AFAIK, there are no sites that cater to FP VBA, that was the intention of
this NG but as you can see it is a Hodge podge.
--
Mike -- FrontPage MVP '97-'02
http://www.websunlimited.com
FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
----------------------------------------------------------------------------
--------------------
If you think I'm doing a good job, let MS know at mvpga@microsoft.com
"Jim Trick" <anonymous@discussions.microsoft.com> wrote in message
news:054101c3ccea$2eff9060$a001280a@phx.gbl...quote:
> I'm attempting to use VBA to provide my users with a form
> that will allow them to "fill in the blanks" each of which
> is a textbox representing unique information (unique to
> the web they are administering). Once the form
> is "submitted", this unique information would be stored in
> a file, then be written to the required positions in to
> the top, left and bottom shared border files for the web
> concerned. The idea is to remove the requirement for users
> to directly edit border files.
>
> I'm at the point where the form information can be
> successfully written to a text file which resides within
> the web structure and now need to read each line from the
> text file back into the successive text boxes on the form.
> (The reason that this is required is to make editing
> changes easy by populating the form with current saved
> values once the form contents have been previously created
> and saved). My thought was that I could do this using an
> array, but I have had no luck. I want to populate each
> textbox in the form with the saved values before
> displaying it.
>
> Any advice would be appreciated, including pointers to any
> websites that deal extensively with VBA issues. I've
> searched for but not found any helpful sites.
>
> Thanks,
>
> Jim
| |
| MD WebsUnlimited.com 2003-12-28, 8:28 am |
| Hi Jim,
The following code assumes that you have a shared border file "top.htm" in the _borders folder. That the top.htm file has two elements an img and a span. The img element has an id of "Logo" and the span has an id of "Caption" Sample HTML follows:
The _borders/top.htm file:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Shared Top Border</title><meta name="Microsoft Theme" content="none">
<meta name="Microsoft Border" content="none">
</head><body><!--webbot bot="purpletext" preview="This border appears in all pages in your Web site. Replace this comment with your own content." -->
<img id="Logo" border="0" src="DHTML/images/9.gif" width="25" height="25"><br><span id="Caption">
My logo caption</span>
</body></html>
In VBA I created the form SharedBorders
The code behind the "Done" button does all the work it is
Private Sub cmdDone_Click()
'
' Purpose: Supply the logo and caption for the top shared border
' Date: 12/27/03
'
Dim oPage As PageWindowEx
Dim oFile As WebFile
Dim oCaption As FPHTMLSpanElement
Dim oLogo As FPHTMLImg
On Error GoTo cmdDone_Error
' We must have values
If txtCaption <> "" Then
If txtLogo <> "" Then
If Not ActiveWeb Is Nothing Then
' this code assumes that there is a file _borders/top.htm
Set oFile = ActiveWeb.LocateFile("_borders/top.htm")
If Not oFile Is Nothing Then
'
' Open the page in FP3
'
Set oPage = oFile.Edit(fpPageViewNoWindow)
If Not oPage Is Nothing Then
'
' if we have a page then get the span tag with an id of Caption and set the new caption in place
'
Set oCaption = oPage.Document.all("Caption")
If Not oCaption Is Nothing Then oCaption.innerText = txtCaption
Set oCaption = Nothing
'
' Get the logo image and replace the src attribute value with our new image location
'
Set oLogo = oPage.Document.all.item("Logo")
If Not oLogo Is Nothing Then oLogo.src = txtLogo
Set oLogo = Nothing
'
' Save the page and remove its resource
'
oPage.Save
Set oPage = Nothing
Else
MsgBox "Unable to open the page ""_borders/top.htm"" for editing", vbOKOnly Or vbInformation, "Shared Borders"
End If
Else
MsgBox "Unable to locate the border file ""_borders/top.htm""", vbOKOnly Or vbInformation, "Shared Borders"
End If
Else
MsgBox "A web must be opened to use this macro", vbOKOnly Or vbInformation, "Shared Borders"
End If
Else
MsgBox "Please supply a URL to the web sites logo", vbOKOnly Or vbInformation, "Shared Border"
End If
Else
MsgBox "Please supply the website caption", vbOKOnly Or vbInformation, "Shared Border"
End If
' end the form
Unload Me
cmdDone_Exit:
On Error Resume Next
' erase all dynamic arrays here and release instances
Exit Sub
cmdDone_Error:
' Collect all unhandled errors
MsgBox Err.Number & ": " & Err.Description, vbCritical, "frmSharedBorders" & ": " & "cmdDone"
Resume cmdDone_Exit
End Sub
===================================================================================
Notes:
You'll need to establish a commnd button to show the form. For testing you can create a module that shows the form.
No file of the values entered was saved per your spec, but I saw no reason to do so.
The code behind the "Browse..." button error handling removed for brevity.
Private Sub cmdBrowse_Click()
if not ActiveWeb is nothing then
txtLogo = FrontPage.ShowPickURLDialog(ActiveWeb.URL)
end if
End Sub
HTH,
--
Mike -- FrontPage MVP '97-'02
http://www.websunlimited.com
FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
------------------------------------------------------------------------------------------------
If you think I'm doing a good job, let MS know at mvpga@microsoft.com
"MD WebsUnlimited.com" <none@none.com> wrote in message news:%235vC7wSzDHA.2712@TK2MSFTNGP09.phx.gbl...quote:
> Hi Jim,
>
> I'm not sure I fully follow the application here but what I believe you wish
> to do is use a VBA form to collect information then save it to a file and to
> the shared border files at specific locations. I don't have this specific
> code and the process is not overly trivial. I may have some time this
> morning and write this up and provide it to you.
>
> AFAIK, there are no sites that cater to FP VBA, that was the intention of
> this NG but as you can see it is a Hodge podge.
>
>
> --
> Mike -- FrontPage MVP '97-'02
> http://www.websunlimited.com
> FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
> ----------------------------------------------------------------------------
> --------------------
> If you think I'm doing a good job, let MS know at mvpga@microsoft.com
>
> "Jim Trick" <anonymous@discussions.microsoft.com> wrote in message
> news:054101c3ccea$2eff9060$a001280a@phx.gbl...
>
>
| |
| Jim Trick 2003-12-28, 5:28 pm |
| Wow! You've been a great help, and have given me a much
better way to do the job. I'm currently modifying your
code and have added a routine to check to see if any files
are already open in edit mode, prompting the user to close
them. I'm also going to add a block that will pre-populate
the text boxes by reading current values in the border
files.
I'll post the modified code here later, and I'm sure
you'll have some comments <g>.
One thing in your reply that I didn't understand, and that
was the mention of the browse error handling. If I'm using
VBA accessed from a FrontPage menu item a web must be
open. Maybe I don't understand what this procedure is
supposed to do.
Once again, many thanks.
Jimquote:
>-----Original Message-----
>Hi Jim,
>
>The following code assumes that you have a shared border
file "top.htm" in the _borders folder. That the top.htm
file has two elements an img and a span. The img element
has an id of "Logo" and the span has an id of "Caption"
Sample HTML follows:quote:
>
>The _borders/top.htm file:
>
><html><head><meta http-equiv="Content-Type"
content="text/html; charset=windows-1252"><title>Shared
Top Border</title><meta name="Microsoft Theme"
content="none">quote:
><meta name="Microsoft Border" content="none">
></head><body><!--webbot bot="purpletext" preview="This
border appears in all pages in your Web site. Replace this
comment with your own content." -->quote:
><img id="Logo" border="0" src="DHTML/images/9.gif"
width="25" height="25"><br><span id="Caption">quote:
>My logo caption</span>
>
></body></html>
>
>In VBA I created the form SharedBorders
>
>
>The code behind the "Done" button does all the work it is
>
>Private Sub cmdDone_Click()
>'
>' Purpose: Supply the logo and caption for the top
shared borderquote:
>' Date: 12/27/03
>'
>
>Dim oPage As PageWindowEx
>Dim oFile As WebFile
>Dim oCaption As FPHTMLSpanElement
>Dim oLogo As FPHTMLImg
>
>On Error GoTo cmdDone_Error
>' We must have values
>If txtCaption <> "" Then
> If txtLogo <> "" Then
> If Not ActiveWeb Is Nothing Then
> ' this code assumes that there is a file
_borders/top.htmquote:
> Set oFile = ActiveWeb.LocateFile
("_borders/top.htm")quote:
> If Not oFile Is Nothing Then
> '
> ' Open the page in FP3
> '
> Set oPage = oFile.Edit(fpPageViewNoWindow)
> If Not oPage Is Nothing Then
> '
> ' if we have a page then get the span
tag with an id of Caption and set the new caption in placequote:
> '
> Set oCaption = oPage.Document.all
("Caption")quote:
> If Not oCaption Is Nothing Then
oCaption.innerText = txtCaptionquote:
> Set oCaption = Nothing
> '
> ' Get the logo image and replace the
src attribute value with our new image locationquote:
> '
> Set oLogo = oPage.Document.all.item
("Logo")quote:
> If Not oLogo Is Nothing Then
oLogo.src = txtLogoquote:
> Set oLogo = Nothing
> '
> ' Save the page and remove its
resourcequote:
> '
> oPage.Save
> Set oPage = Nothing
> Else
> MsgBox "Unable to open the
page ""_borders/top.htm"" for editing", vbOKOnly Or
vbInformation, "Shared Borders"quote:
> End If
> Else
> MsgBox "Unable to locate the border
file ""_borders/top.htm""", vbOKOnly Or
vbInformation, "Shared Borders"quote:
> End If
> Else
> MsgBox "A web must be opened to use this
macro", vbOKOnly Or vbInformation, "Shared Borders"quote:
> End If
> Else
> MsgBox "Please supply a URL to the web sites
logo", vbOKOnly Or vbInformation, "Shared Border"quote:
> End If
>Else
> MsgBox "Please supply the website caption", vbOKOnly
Or vbInformation, "Shared Border"quote:
>End If
>' end the form
>Unload Me
>
>cmdDone_Exit:
> On Error Resume Next
> ' erase all dynamic arrays here and release instances
> Exit Sub
>cmdDone_Error:
> ' Collect all unhandled errors
> MsgBox Err.Number & ": " & Err.Description,
vbCritical, "frmSharedBorders" & ": " & "cmdDone"quote:
> Resume cmdDone_Exit
>
>End Sub
>
>==========================================================
=========================quote:
>
>Notes:
>
>You'll need to establish a commnd button to show the
form. For testing you can create a module that shows the
form.quote:
>No file of the values entered was saved per your spec,
but I saw no reason to do so.quote:
>
>The code behind the "Browse..." button error handling
removed for brevity.quote:
>
>Private Sub cmdBrowse_Click()
> if not ActiveWeb is nothing then
> txtLogo = FrontPage.ShowPickURLDialog
(ActiveWeb.URL)quote:
> end if
>End Sub
>
>
>HTH,
>
>--
>Mike -- FrontPage MVP '97-'02
>http://www.websunlimited.com
>FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
>----------------------------------------------------------
--------------------------------------quote:
>If you think I'm doing a good job, let MS know at
mvpga@microsoft.comquote:
>
>
>
>"MD WebsUnlimited.com" <none@none.com> wrote in message
news:%235vC7wSzDHA.2712@TK2MSFTNGP09.phx.gbl...[QUOTE][color=darkred]
what I believe you wish[QUOTE][color=darkred]
save it to a file and to[QUOTE][color=darkred]
have this specific[QUOTE][color=darkred]
some time this[QUOTE][color=darkred]
was the intention of[QUOTE][color=darkred]
Compatible[QUOTE][color=darkred]
--------------------[QUOTE][color=darkred]
mvpga@microsoft.com[QUOTE][color=darkred]
in message[QUOTE][color=darkred]
form[QUOTE][color=darkred]
which[QUOTE][color=darkred]
to[QUOTE][color=darkred]
stored in[QUOTE][color=darkred]
to[QUOTE][color=darkred]
web[QUOTE][color=darkred]
users[QUOTE][color=darkred]
within[QUOTE][color=darkred]
the[QUOTE][color=darkred]
form.[QUOTE][color=darkred]
created[QUOTE][color=darkred]
an[QUOTE][color=darkred]
to any[QUOTE][color=darkred]
| |
| MD WebsUnlimited.com 2003-12-28, 11:29 pm |
| On the form the URL is supplied by clicking on the "Browse..." button. I
supplied the code (behind it) without any error handling.
If this is a controlled process, that is you never wish to allow the user to
manipulate the border files, you can utilize GPO and WSH to disable specific
functionality in FP.
BTW, are you aware that Shared Borders are being depreciated in favor of
DWT? If not, you should take some time to learn the differences -- DWT is a
much better system.
--
Mike -- FrontPage MVP '97-'02
http://www.websunlimited.com
FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
----------------------------------------------------------------------------
--------------------
If you think I'm doing a good job, let MS know at mvpga@microsoft.com
"Jim Trick" <anonymous@discussions.microsoft.com> wrote in message
news:045701c3cd84$efa019d0$a001280a@phx.gbl...[QUOTE][color=darkred]
> Wow! You've been a great help, and have given me a much
> better way to do the job. I'm currently modifying your
> code and have added a routine to check to see if any files
> are already open in edit mode, prompting the user to close
> them. I'm also going to add a block that will pre-populate
> the text boxes by reading current values in the border
> files.
>
> I'll post the modified code here later, and I'm sure
> you'll have some comments <g>.
>
> One thing in your reply that I didn't understand, and that
> was the mention of the browse error handling. If I'm using
> VBA accessed from a FrontPage menu item a web must be
> open. Maybe I don't understand what this procedure is
> supposed to do.
>
> Once again, many thanks.
>
> Jim
> file "top.htm" in the _borders folder. That the top.htm
> file has two elements an img and a span. The img element
> has an id of "Logo" and the span has an id of "Caption"
> Sample HTML follows:
> content="text/html; charset=windows-1252"><title>Shared
> Top Border</title><meta name="Microsoft Theme"
> content="none">
> border appears in all pages in your Web site. Replace this
> comment with your own content." -->
> width="25" height="25"><br><span id="Caption">
> shared border
> _borders/top.htm
> ("_borders/top.htm")
> tag with an id of Caption and set the new caption in place
> ("Caption")
> oCaption.innerText = txtCaption
> src attribute value with our new image location
> ("Logo")
> oLogo.src = txtLogo
> resource
> page ""_borders/top.htm"" for editing", vbOKOnly Or
> vbInformation, "Shared Borders"
> file ""_borders/top.htm""", vbOKOnly Or
> vbInformation, "Shared Borders"
> macro", vbOKOnly Or vbInformation, "Shared Borders"
> logo", vbOKOnly Or vbInformation, "Shared Border"
> Or vbInformation, "Shared Border"
> vbCritical, "frmSharedBorders" & ": " & "cmdDone"
> =========================
> form. For testing you can create a module that shows the
> form.
> but I saw no reason to do so.
> removed for brevity.
> (ActiveWeb.URL)
> --------------------------------------
> mvpga@microsoft.com
> news:%235vC7wSzDHA.2712@TK2MSFTNGP09.phx.gbl...
> what I believe you wish
> save it to a file and to
> have this specific
> some time this
> was the intention of
> Compatible
> --------------------
> mvpga@microsoft.com
> in message
> form
> which
> to
> stored in
> to
> web
> users
> within
> the
> form.
> created
> an
> to any
| |
| Lisa Wollin \(Microsoft\) 2003-12-31, 1:29 pm |
| Hi, Jim,
There are a couple places that you can get VBA help. Of course, the
newsgroups are great. In addition, the FrontPage 2002 SDK (which you can
view online at
http://msdn.microsoft.com/library/d...veloperskit.asp
or download from
http://www.microsoft.com/downloads/...&displaylang=en)
contains several examples of working with the FP object models. In
addition, we are working to add developer information for FrontPage 2003 to
the new FrontPage developer pages on MSDN at
http://msdn.microsoft.com/frontpage.
As always, we appreciate your feedback, so if you are unable to find
something that you need, please use the Feedback link on any of the pages.
--
Lisa Wollin
Programmer Writer
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
"MD WebsUnlimited.com" <none@none.com> wrote in message
news:%235vC7wSzDHA.2712@TK2MSFTNGP09.phx.gbl...quote:
> Hi Jim,
>
> I'm not sure I fully follow the application here but what I believe you
wishquote:
> to do is use a VBA form to collect information then save it to a file and
toquote:
> the shared border files at specific locations. I don't have this specific
> code and the process is not overly trivial. I may have some time this
> morning and write this up and provide it to you.
>
> AFAIK, there are no sites that cater to FP VBA, that was the intention of
> this NG but as you can see it is a Hodge podge.
>
>
> --
> Mike -- FrontPage MVP '97-'02
> http://www.websunlimited.com
> FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
> --------------------------------------------------------------------------
--quote:
> --------------------
> If you think I'm doing a good job, let MS know at mvpga@microsoft.com
>
> "Jim Trick" <anonymous@discussions.microsoft.com> wrote in message
> news:054101c3ccea$2eff9060$a001280a@phx.gbl...
>
>
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|