Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    FP2000 macro to set HTTP-Equiv keywords (FP2000 SR1)

    I would like to be able to create a macro to add keywords to certain pages in my web. I have found reference in the help file to methods for reading meta tags but have not been able to find any way to set them. (my searching through help is somewhat stunted because I keep getting protection exceptions in MSOHELP - despite having done a detect&repair, sigh!)
    Anyone know of a way to do this? I'm guessing the alternative is to simply add the relevant line in HTML view.

  2. #2
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: FP2000 macro to set HTTP-Equiv keywords (FP2000 SR1)

    Just to be clear - the pages you want to add the meta tags to already exist?

    Otherwise - the method is to create a template that includes your metatags. Then the pages based on those templates will include the metatags.
    I'll think about a macro to update existing pages.


    Cheers
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FP2000 macro to set HTTP-Equiv keywords (FP2000 SR1)

    Thanks for the response. Yes, that's right, the pages already exist (they are at www.self-heal.com).
    I confess I had a sinking feeling when I read your reply suggesting the use of a template including the metatags to create the pages. Utterly brilliant now you mention it, but for a neophyte website creator I have to say that metatags were the furthest thing from my mind when I commenced this project.
    In playing around with a prototype macro I have got this far...
    Public Sub AddTags()
    Dim myDocObject As FPHTMLDocument
    Dim myDocHTML As String
    Dim newDocHTML As String
    Dim myKeywords As String
    Dim insertPoint As Long
    Dim mySearchTag As String

    ' Set the string of keywords to add
    myKeywords = "<meta http-equiv=""keywords"" content=""homeopathy, homoeopathy, naturopathy, healing, natural health, "
    myKeywords = myKeywords + "chiropractor, bowen therapy, bowen technique, bowen, massage, "
    myKeywords = myKeywords + "weight loss, herbalism, herbalist, new zealand herbs, zealand, "
    myKeywords = myKeywords + "self heal, nature cure, natural health, alternative therapies, "
    myKeywords = myKeywords + "complementary medicine""" + vbCrLf

    'Grab the document to add keywords to
    Set myDocObject = ActivePageWindow.ActiveDocument
    'Place the keywords immediately after the <head> tag, assuming it is there
    mySearchTag = "<head>"

    myDocHTML = myDocObject.DocumentHTML
    'Where is that <head> tag
    insertPoint = InStr(myDocHTML, mySearchTag)

    If insertPoint > 0 Then
    'we want the position of the start of the *next* tag
    insertPoint = insertPoint + 1
    insertPoint = InStr(insertPoint, myDocHTML, "<", vbTextCompare)
    newDocHTML = Left$(myDocHTML, insertPoint - 1) + myKeywords + Mid$(myDocHTML, insertPoint)
    myDocHTML = newDocHTML
    End If

    Debug.Print myDocHTML
    'I see the modified HTML code in the immediate window, so this works so far - jump about, clap paws!!
    End Sub

    (yes it's crude but, hey, I'm no programmer!!)
    Having created the modified string of HTML, I cannot see how to put it into the FrontPage document. That is, I have not found the way to "set" the "DocumentHTML" string, even though the FP help says it is a read/write string. Heeeeellllpppp!!!
    Cheers, Ian

  4. #4
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: FP2000 macro to set HTTP-Equiv keywords (FP2000 SR1)

    I won't be able to test your macro for a while - however, here are some articles from the MSKB that might be helpful.

    Q241730 Describes how to remove Meta tags from a web without opening individual files.
    Q238423How to add HTML to a file using VBA.

    Tell us what you come up with!
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FP2000 macro to set HTTP-Equiv keywords (FP2000 SR1)

    Those articles look like they may be *just* what I'm looking for. I notice that one of the code segments mutters something about files having to be closed in order to alter the HTML which may explain some of the trouble I was having. (I'm sure that in the past I've created the odd trivial vba macro to manipulate things in Word & Excel and have never had to make sure the relevant file was closed <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>).
    I appreciate your help & will certainly let you know how I get on (i.e. report back on which is more fun: struggling with the intricacies of vba in FrontPage or repeatedly banging my head on the desk - too close to call at this point)!!

  6. #6
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FP2000 macro to set HTTP-Equiv keywords (FP2000 SR1)

    OK, we have success. The following churns its way through each folder/file in the web adding meta tags as it goes. It excludes FP generated folders, i.e. those whose names start with an underscore. It also checks which folders files to process - no point trying to process images, etc.

    Catharine, thank you *very* much for your help - those knowledge base references turned out to be very useful!!

    Sub MetaTagMyWeb()
    'Moves through each folder/file in the web and adds the
    'keyword/contents meta tag to selected files

    Dim myMsgBoxResults As VbMsgBoxResult
    Dim myCurrentFolder As WebFolder

    'Check that we have a web to work with and, if not, quit
    If ActiveWebWindow.Web Is Nothing Then
    myMsgBoxResults = MsgBox("This macro requires that the web be opened prior to running.", _
    vbOKOnly + vbExclamation)
    Exit Sub
    End If

    'Editing the HTML requires that no files be open, check for this...
    If ActiveWeb.ActiveWebWindow.PageWindows.Count <> 0 Then
    myMsgBoxResults = MsgBox("Please close all web pages (but not the web) before running this macro", _
    vbOKOnly + vbExclamation)
    Exit Sub
    End If

    'Do all files in the root folder
    Set myCurrentFolder = ActiveWeb.RootFolder
    ProcessFiles myCurrentFolder

    'Tell the world we're done
    myMsgBoxResults = MsgBox("Meta tags added to selected pages!", _
    vbOKOnly + vbInformation)

    End Sub
    Sub ProcessFiles(myFolder As WebFolder)

    Dim myCurrentFile As WebFile
    Dim myFileName As String
    Dim myResponse As VbMsgBoxResult
    Dim mySubFolder As WebFolder

    For Each myCurrentFile In myFolder.Files
    myFileName = myCurrentFile.Name
    If Left$(UCase(myCurrentFile.Extension), 3) = "HTM" Then
    'Check that this file is to be processed
    myResponse = MsgBox(myFileName, vbQuestion + vbYesNo, _
    "Process this file?")
    If myResponse = vbYes Then
    'Process it
    AddTags myCurrentFile
    End If
    End If
    Next myCurrentFile

    'Loop through any subfolders in this folder
    For Each mySubFolder In myFolder.Folders
    'Omit folders whose names begin with an underscore as these are FP folders and won't
    'have any of my files in them
    If Left$(mySubFolder.Name, 1) <> "_" Then
    myFileName = mySubFolder.Name
    myResponse = MsgBox(myFileName, vbQuestion + vbYesNo, _
    "Process this folder?")
    If myResponse = vbYes Then ProcessFiles mySubFolder
    End If
    Next mySubFolder

    End Sub
    Public Sub AddTags(myFile As WebFile)
    'Adds the keyword and contents strings as a meta tag to myFileName

    Dim myDocObject As FPHTMLDocument
    Dim myFileName As String
    Dim myPageWindow As PageWindow
    Dim myTag As IHTMLElement
    Dim myKeywords As String

    ' Set the string of keywords to add
    myKeywords = "<meta http-equiv=""keywords"" content=""homeopathy, homoeopathy, naturopathy, healing, natural health, "
    myKeywords = myKeywords + "chiropractor, bowen therapy, bowen technique, bowen, massage, pregnancy, "
    myKeywords = myKeywords + "weight loss, herbalism, herbalist, new zealand herbs, zealand, natural remedy, "
    myKeywords = myKeywords + "self heal, nature cure, natural health, alternative therapies, natural remedies, "
    myKeywords = myKeywords + "alternative health, complementary medicine, homeopath, homeopathic"">"

    'Grab the document to add keywords to
    Set myPageWindow = myFile.Edit(fpPageViewNormal)
    Set myDocObject = myPageWindow.Document
    myFileName = "Now processing " & myFile.Name

    'Locate the first (only?!?!) <head> tag
    Set myTag = myDocObject.all.tags("head").Item(0)
    'myTag points to the head tag - place meta tag immediately after that
    Call myTag.insertAdjacentHTML("AfterBegin", myKeywords)

    'Save and close the document
    myPageWindow.SaveAs myPageWindow.Document.Url
    myPageWindow.Close False

    End Sub

  7. #7
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: FP2000 macro to set HTTP-Equiv keywords (FP2000 SR1)

    Congratulations!
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  8. #8
    Star Lounger
    Join Date
    Feb 2001
    Location
    Auckland, North Island, New Zealand
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FP2000 macro to set HTTP-Equiv keywords (FP2000 SR1)

    This is fantastic just what I needed.

    Have you enhanced this code at all, specifically I am looking for any ideas as to how to check for existing keywords tag and if different append new content esle put the new content only

    In otherwords if you run this code twice how do you stop two keyword metas being created?

    Thanks
    Simon

  9. #9
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FP2000 macro to set HTTP-Equiv keywords (FP2000 SR1)

    Hi Simon
    No, I haven't tried to do what you are suggesting but I see no reason why it cannot be done relatively easily. Referring to the macro, there is a bit where it finds the <HEAD> tag:
    'Locate the first (only?!?!) <head> tag
    Set myTag = myDocObject.all.tags("head").Item(0)
    Presumably you could first find the <META> tag using something like:
    Set myMetaTag = myDocObject.all.tags("meta").Item(0)
    and then use normal string processing functions to search the meta tag for what is there. Now there is just one catch - I'm not sure how you modify pre-existing content (i.e. where you want to append to the existing meta tags). You may need to holler for help with that bit, but in principle what you want to do should be straightforward. Sorry I'm not able to offer any more help but what you see is the sum total of my FP2000 macro experience/expertise. Good luck!!
    Regards
    Ian

  10. #10
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: FP2000 macro to set HTTP-Equiv keywords (FP2000 SR1)

    I haven't tested this yet - but I wonder if one was checking for pre-existing meta tags, could you insert this into your code?
    <pre>
    Public Sub AddTags(myFile As WebFile)
    'Adds the keyword and contents strings as a meta tag to myFileName

    Dim myDocObject As FPHTMLDocument
    Dim myFileName As String
    Dim myPageWindow As PageWindow
    Dim myTag As IHTMLElement
    Dim myKeywords As String

    ' Set the string of keywords to add
    myKeywords = "<meta http-equiv=""keywords"" content=""homeopathy, homoeopathy, "
    myKeywords = myKeywords + "chiropractor, bowen therapy, bowen technique, "
    myKeywords = myKeywords + "alternative health, complementary medicine "">"

    'Grab the document to add keywords to
    Set myPageWindow = myFile.Edit(fpPageViewNormal)
    Set myDocObject = myPageWindow.Document
    myFileName = "Now processing " & myFile.Name
    <font color=blue>
    If ActiveDocument.all.tags("meta").Item("Keywords").o uterHTML = "" Then
    </font color=blue>
    'Locate the first (only?!?!) <head> tag
    Set myTag = myDocObject.all.tags("head").Item(0)
    'myTag points to the head tag - place meta tag immediately after that
    Call myTag.insertAdjacentHTML("AfterBegin", myKeywords)

    'Save and close the document
    myPageWindow.SaveAs myPageWindow.Document.Url
    myPageWindow.Close False
    <font color=blue>
    End If
    </font color=blue>

    End Sub
    </pre>

    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  11. #11
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FP2000 macro to set HTTP-Equiv keywords (FP2000 SR1)

    What you are suggesting should work fine in the instance where you are looking to add meta tags where none exist. What Simon was looking for was some code that would also inspect any existing meta tags and append the new tags if they were different which is a variant on what you are suggesting. Nevertheless I like your approach as an elegant way to find if there are no pre-existing keywords and, if so, add the string. It should work and I shall give it a whirl when I get some time... (he says, looking at the piles on his desk <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15> ). Thanks (again) for your help!

  12. #12
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: FP2000 macro to set HTTP-Equiv keywords (FP2000 SR1)

    I haven't posted back on this yet - because I haven't made it work yet, I got error messages if the tag didn't exist. It couldn't find the non-existing tag and barfed up the error msg instead <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>. What I WAS able to do was modify this to put in a whole group of meta tags simultaneously, not just keywords, but author, robots etc.
    So it was still worth playing with.

    Cheers
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  13. #13
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FP2000 macro to set HTTP-Equiv keywords (FP2000 SR1)

    Well done on the production line! Just what these computery things are good for - lots of repetitive automated data entry.
    You piqued my interest about erors with missing tags and here is what I've discovered - the MetaTags collections lets you look at the various values and you can determine from that whether the "keywords" tag exists and, if so, what its contents are. The following bit of code will display a message box for each file in your web either showing the keywords (if they exist) or saying there are none. Do not use it on a web with lots of files as it is as boring as watching paint dry <img src=/S/doze.gif border=0 alt=doze width=15 height=15> . The big remaining puzzle is this: assuming that I want to modify files that already have keywords - how do I modify the existing HTTP-EQUIV? From what I have seen in the help files this stuff appears to be read-only which is really puzzling as it is possible to ADD new stuff so there must be a way to modify what already exists?
    Anyway, the code follows...
    Sub ShowKeywords()
    Dim myWeb As WebEx
    Dim myFiles As WebFiles
    Dim myFile As WebFile
    Dim myMetaTags As MetaTags
    Dim myMetaTag As Variant
    Dim myFileName As String
    Dim myMetaTagName As String
    Dim myReturnInfo As String
    Dim myKeywords As String
    Dim Response As Integer

    Set myWeb = ActiveWeb
    Set myFiles = myWeb.RootFolder.Files

    With myWeb
    For Each myFile In myFiles
    myReturnInfo = "No keywords present in " & myFile.Name
    Set myMetaTags = myFile.MetaTags
    For Each myMetaTag In myMetaTags
    myMetaTagName = myMetaTag
    If InStr(1, UCase(myMetaTagName), "KEYWORDS", 1) > 0 Then
    myKeywords = myFile.MetaTags.Item("http-equiv=keywords") ' this might be safer as .Item(myMetaTagName)
    myReturnInfo = "File " & myFile.Name & " has keywords: " & myKeywords
    End If

    Next
    myResponse = MsgBox(myReturnInfo, vbOKOnly)
    Next
    End With

    End Sub

  14. #14
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: FP2000 macro to set HTTP-Equiv keywords (FP2000 SR1)

    Hmmm, getting an error at line: Dim myMetaTags As MetaTags

    Well I suppose one would have to read the current keywords into a string and then add the new keywords to them.

    untested of course
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  15. #15
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: FP2000 macro to set HTTP-Equiv keywords (FP2000 SR1)

    <P ID="edit" class=small>(Edited by WebGenii on 11-Feb-03 23:22. )</P>Got it to work by modifying as follows:
    <pre>Sub ShowKeywords()
    Dim myWeb As WebEx
    Dim myFiles As WebFiles
    Dim myFile As WebFile
    'Dim myMetaTags As MetaTags - arrgh the reason this didn't work
    ' is I renamed a module MetaTags DUUUH!
    Dim myMetaTag As Variant
    Dim myFileName As String
    Dim myMetaTagName As String
    Dim myReturnInfo As String
    Dim myKeywords As String
    Dim Response As Integer

    Set myWeb = ActiveWeb
    Set myFiles = myWeb.RootFolder.Files

    With myWeb
    For Each myFile In myFiles
    myReturnInfo = "No keywords present in " & myFile.Name
    Set myMetaTags = myFile.MetaTags
    For Each myMetaTag In myMetaTags
    myMetaTagName = myMetaTag
    If InStr(1, UCase(myMetaTagName), "KEYWORDS", 1) > 0 Then
    myKeywords = myFile.MetaTags.Item(myMetaTagName) 'edited as per suggestion
    myReturnInfo = "File " & myFile.Name & " has keywords: " & myKeywords
    End If

    Next
    myResponse = MsgBox(myReturnInfo, vbOKOnly)
    Next
    End With

    End Sub
    </pre>

    One oddity - it only handles the top layer of files in the web - any files in subfolders are ignored. And now, come to think of it I think the other macro had the same problem too.
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •