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

    Macro in FrontPage

    I can record a macro in Word to replace all and then just amend what is searched for and what is replaced.
    I need the same macro in FrontPage as I have to do some large scale replacing. FP doesn't have a Record feature so I can't get my starter. Can someone help me please?

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Macro in FrontPage

    Hi Peter,

    Um, paste the text into Word, do the replace, then paste back into FrontPage? <img src=/S/crazy.gif border=0 alt=crazy width=15 height=15>

    Seriously, a look at the FrontPage object model via the Object Browser doesn't reveal much of any use - there is no Selection, Range, Content, Find nor Replace object available in FrontPage VBA.

    There is, however, the Replace function, which given the lack of alternatives, just might be your ticket:
    The idea would be to assign the HTML code of the page/document (or whatever you call a FrontPage file) to a string variable, run the Replace function on it, and then replace the original HTML code with the string output of the Replace function.

    With the caveat that I've never used FrontPage, let alone coded it, here is an example that kinda sorta works:

    Public Sub HTMLReplace()
    'FrontPage 2000
    Dim strHTMLCode As String
    Dim strReplOutput As String
    strHTMLCode = ActiveDocument.body.innerText
    strReplOutput = Replace(strHTMLCode, "stuff", "material")
    ActiveDocument.body.innerText = strReplOutput
    End Sub

    - where "stuff" in the Find text, and "material" is the Replace text.

    I found that this ran when in Normal view, but produced an error when in HTML view.

    Try this on a copy of your file - it may be doing unwanted stuff - I wouldn't know!<g>

    Hope this helps,
    Gary

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

    Re: Macro in FrontPage

    Gary
    I get the same result and of course it's in the HTML view that I need the macro to run, so frustrating. Particularly as FP has a Find and Replace function, so close and so far.
    Hey ho! Many thanks for looking.
    Just as an afterthought, I know in Word that if you give a macro the name of a dialog box, you can change the default settings. In the good old days of Float over text being a word default, you could change that as below
    Sub InsertPicture()
    '
    ' InsertPicture Macro
    ' Inserts a picture from a graphics file
    ' This macro changes default
    With Dialogs(wdDialogInsertPicture)
    .FloatOverText = False
    .Show
    End With
    End Sub
    I wonder if there's something similar in FP.

    Peter

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Macro in FrontPage

    Hi again,

    The 'intercepting built-in commands' was something I thought of too, but there doesn't seem to be anywhere in FP where you can go find out the names of them.

    Although the macro only runs when you're in Normal view, it does do the find/replace on the HTML code itself, so you still should give a try to running it in Normal view, to see if does anything useful.

    Gary

  5. #5
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro in FrontPage

    Hi Peter,

    How 'bout doing it from Word? The following makes the change to all *.htm docs in a folder. If you want to include subfolders, set the SearchSubFolders property to true. You can also tweak the search parameters.

    Sub A1HTMReplace()
    '
    ' A1HTMReplace Macro
    ' Macro created 5/14/2001 by Christopher Green
    '
    Dim strFolder As String
    Dim strFind As String, strReplace As String


    strFind = InputBox("Enter the string to look for.", "Find")
    strReplace = InputBox("Enter the string to replace.", "Replace")

    With Dialogs(wdDialogCopyFile)
    If .Display = -1 Then strFolder = .Directory
    End With

    With Application.FileSearch
    .FileName = ".htm"
    .LookIn = strFolder
    .Execute
    .SearchSubFolders = False
    For i = 1 To .FoundFiles.Count
    WordBasic.disableautomacros
    Documents.Open .FoundFiles(i), Format:=wdOpenFormatText
    Selection.Find.ClearFormatting
    With Selection.Find
    .Forward = True
    .Wrap = wdFindStop
    .Text = strFind
    .Replacement.Text = strReplace
    .Execute Replace:=wdReplaceAll
    End With
    ActiveDocument.Close wdSaveChanges
    Next i
    End With

    End Sub

    HTH,

    Chris

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

    Re: Macro in FrontPage

    Gary

    re your first para: so I found later! I tried the Ctrl | Alt | + combination that works in Word but it didn't even change the cursor in FP.

    re your second para: unfortunately what I am trying to delete only appears in the HTML code.

    Thanks anyway. I appreciate the time you have spent on this.

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

    Re: Macro in FrontPage

    Chris

    Unfortunately what I am trying to delete only appears in the HTML code rather than the text that is read, so I guess your macro will not find it.

    I don't have access to the files I want at the moment but from your description, the macro will help me with some other work so your time was not wasted. Indeed, the time involved in the other task makes the need for this macro greater than the other one that is proving elusive!

    Many thanks.

  8. #8
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro in FrontPage

    Hi Peter,

    The code opens the pages as text documents. It doesn't read it like a web page, it's like opening it in notepad. So, it should do what you need. I perform many operations on HTM files that are part of compiled html help projects without a hitch. Here's the relevant line...

    Documents.Open .FoundFiles(i), Format:=wdOpenFormatText

    HTH,

    Chris

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

    Re: Macro in FrontPage

    Life just got better! One macro fulfilling two requirements.
    I'll be playing with the macro as soon as I get into the office tomorrow morning.
    Again thanks.

  10. #10
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Macro in FrontPage

    Hi Peter,

    Just wanted to note that the point Chris made about the macro working on the HTML, even though you are not currently viewing the HTML folder, was the same point I was making above re the macro I suggested :-).

    However I definitely recommend using Chris' rather than mine - it's a really nifty idea!

    Gary

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

    Re: Macro in FrontPage

    Sorry, I misunderstood you.
    I thought your macro was searching for something in Normal view and if it found it there, it replaced it changing the HTML in the process in the same way as if you edited text there. As what I am seeking is not in the normal view, that would not have worked.
    Now that you have pointed out that your macro is in fact searching in the code, it has an advantage over Chris' solution for one of the operations I need to perform.
    For the other operation, then Chris' solution is, as you say, nifty. Just need to be careful you don't use words that could be within a tag!
    Thank you for following this through.

  12. #12
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro in FrontPage

    Aw, shucks, Gary... thanks...

    Hey. How 'bout a smiley for an embarrassed little guy accepting praise?

Posting Permissions

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