Results 1 to 6 of 6

Thread: Replace Macro

  1. #1
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Replace Macro

    I know something about writing macros in Word but in FrontPage, I'm lost. Would someone please help me with a simple macro.
    When in the HTML tab, I want to be able to search for all instances and replace them with nothing. (Why is a long story!).
    Rather than continually bring up the Replace dialog, I want to be able to click an icon to run this macro.
    In the hope that this macro is as simple as it seems, does someone have the time to help me please?

  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: Replace Macro

    I'll have to check my FP tonight when I get home - but in the meantime try cross posting a link to this thread in the VBA board. You might catch a VBA wizard more quickly there! <img src=/S/exclamation.gif border=0 alt=exclamation width=15 height=15>
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  3. #3
    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: Replace Macro

    Have you tried doing your find and replace from the folder view? You get a Replace Across Web Button and a Find in HTML option.
    Attached Images Attached Images
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  4. #4
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Replace Macro

    I am using FP with an Online Learning program, rather than creating a web site. The folder view shows nothing.
    I will post something on the VBA side as suggested.
    Many thanks.

  5. #5
    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: Replace Macro

    For those that are interested - the thread continues here <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=vb&Number=38334&page=&view= &sb=&vc=1>http://www.wopr.com/cgi-bin/w3t/showflat.p...&view=&sb=&vc=1</A>
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  6. #6
    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: Replace Macro

    You can see it's been a long time since Peter's original post, but I've been thinking about his problem for quite awhile. Or at least my version of the problem.
    I feel it is important to replace all bold and italics tags in a page with the strong and em tags. I know the find dialog box is available, but this turns into multiple steps. I also want to do a single pages at a time, that way I have a check on whether I've worked on a page or not.
    Anyhow, I've finally come up with a macro - and I think you'll be able to see where you could modify it for other things.
    <pre>Sub ReplaceBoldItalics()
    Dim objDoc As FPHTMLDocument
    Dim objElement As IHTMLElement
    Dim currElement, strOutPut As String

    Const newStrongON As String = ""
    Const newStrongOFF As String = "
    "
    Const BoldOn As String = ""
    Const BoldOff As String = "
    "
    Const newEmOn As String = ""
    Const newEmOff As String = "
    "
    Const ItalicsOn As String = ""
    Const ItalicsOff As String = "
    "

    Set objDoc = ActiveDocument
    'Document must be in Normal view or else the outerHTML command fails.
    ActivePageWindow.ViewMode = fpPageViewNormal

    'First pass will replace bold command with Strong command.
    'Make the entire document into a string - necessary for VBA replace.
    currElement = objDoc.DocumentHTML
    'The OutPut string (strOutPut) is the entire document with the bold on tag replaced
    ' by the STRONG command, the vbTextCompare is necessary, so that the Replace command
    ' will disregard the case of the tag.
    strOutPut = Replace(currElement, BoldOn, newStrongON, , , vbTextCompare)
    'Now, the OutPut string runs through the replacement again, this time replacing
    ' the bold off tag with the /STRONG tag
    strOutPut = Replace(strOutPut, BoldOff, newStrongOFF, , , vbTextCompare)

    'Second pass will replace italics command with EM command.
    'Now, the OutPut string runs through the replacement again, this time replacing
    ' the italics tags with the EM tags.
    strOutPut = Replace(strOutPut, ItalicsOn, newEmOn, , , vbTextCompare)
    strOutPut = Replace(strOutPut, ItalicsOff, newEmOff, , , vbTextCompare)

    'Looks for the HTML On tag.
    For Each objElement In objDoc.all.tags(tagName:="html")
    'Writes the OutPut string into the document between the HTML ON/OFF tags.
    objElement.outerHTML = strOutPut
    Next objElement

    End Sub
    </pre>


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

Posting Permissions

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