Results 1 to 13 of 13
  1. #1
    2 Star Lounger
    Join Date
    Dec 2004
    Location
    Stoney Creek, Ontario
    Posts
    196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Defining variable problem re: html (2003)

    I am trying to make global changes to a large set of html files; specifically the font, colour and size. Altering a macro Hans was kind enought to provide me, I am trying to loop through these html files to make changes but I think I'm stuck right at the beginning with the Dim As. How do I declare the html file as a variable? Here's the line that gives me the error:

    Set doc = html.Open

    The error points to html and says '"variable not defined".

    (Sorry - I'm very new at this!)

    Deb


    The error is pointing to html

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Defining variable problem re: html (2003)

    Can you post some more of the macro? It's hard to know what you're doing from a single line.

  3. #3
    2 Star Lounger
    Join Date
    Dec 2004
    Location
    Stoney Creek, Ontario
    Posts
    196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Defining variable problem re: html (2003)

    After a bit of fiddling around, I don't get the "variable not defined" error any more, but now the code simply doesn't work. I have de-bugged it but I'm not getting any hints as to what is wrong with it. Here it is...and thanks again Hans.

    Sub ChangeFontProperties()
    ' Path - make sure it ends in a backslash
    Const strPath = "ZataCC Test"
    ' Variables
    Dim strFile As String
    Dim html As Document
    Dim strTitle As String

    On Error GoTo ErrHandler

    ' Turn of screen updating (doesn't help much)
    Application.ScreenUpdating = False
    ' First file name
    strFile = Dir(strPath & "*.htm")
    ' Loop through files
    Do While Not strFile = ""
    strTitle = Mid(strFile, 1, InStr(1, strFile, ".") - 1)
    ' Open document
    Set doc = Documents.Open _
    (FileName:=strPath & strFile, AddToRecentFiles:=False)
    Selection.WholeStory
    With Selection.Font
    .Name = "Verdana"
    .Size = 12
    .Color = 4805720
    End With
    ' Close and save
    doc.Close SaveChanges:=wdSaveChanges
    ' Get next document name
    strFile = Dir
    Loop
    MsgBox "The files have been converted."
    Exit Sub

    ErrHandler:
    ' Display error message
    MsgBox Err.Description, vbExclamation

    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Defining variable problem re: html (2003)

    In the first place, the declaration

    Dim html As Document

    should be

    Dim doc As Document

    In the second place, you set a variable strTitle:

    strTitle = Mid(strFile, 1, InStr(1, strFile, ".") - 1)

    but you don't do anything with this variable. What was your intention?

    Apart from that, the code works, if you supply a folder that does contain .htm files (are you sure the extension is .htm and not .html?)

  5. #5
    2 Star Lounger
    Join Date
    Dec 2004
    Location
    Stoney Creek, Ontario
    Posts
    196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Defining variable problem re: html (2003)

    I've change the declaration and the strTitle line was there in error....I missed taking that line out.

    I have checked the file extensions and they are .html so I have altered the macro to reflect that and the path is correct. When I run the macro, no errors come up but the files have not changed. I'm not sure what else to check.

    Could it have anything to do with the folder that these html files reside in having sub files that contain each document's header information?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Defining variable problem re: html (2003)

    When you look at the folder after running the macro, has the last modified date of the .html files changed to the date/time you ran the macro?

  7. #7
    2 Star Lounger
    Join Date
    Dec 2004
    Location
    Stoney Creek, Ontario
    Posts
    196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Defining variable problem re: html (2003)

    Oh, good thinking Hans. This is interesting...the file folders I mentioned in my previous post all say modified March 8, 2006. The actual html documents don't. What does that mean?

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Defining variable problem re: html (2003)

    Strange. Try the following: click in the first line of the code (Sub ...) and press F8 to start single-stepping through the code. Each time you press F8, you will execute one instruction. You can switch back and forth between Word and the Visual Basic Editor using Alt+Tab or the Windows task bar. Can you see that the HTML files are being opened and modified?

  9. #9
    2 Star Lounger
    Join Date
    Dec 2004
    Location
    Stoney Creek, Ontario
    Posts
    196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Defining variable problem re: html (2003)

    The plot thickens. Doing as you instructed, pressing F8, the yellow line jumps from "Do While..." to the Msg Box line and skips all the good bits in between. That being the case, I can't see how the file folders containing the headers are being modified at all.

    Edit: just a thought. Seeing as I'm very new at this, could not indenting lines properly in the code have anything to do with it?

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Defining variable problem re: html (2003)

    While you're at it... you may well want to redesign your pages to take advantage of a shared style sheet. In most cases, <font> tags can be completely replaced with one page of style definitions and a few <span class="specialformat"></span> tag pairs. Of course, this might be beyond your brief, in which case, "never mind." <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Edit: Oh... you're actually editing them as Word documents. I had assumed you were simply editing them as text files. Please ignore this post.

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Defining variable problem re: html (2003)

    Indenting code is merely an aide for viewing and understanding the code. Although I highly recommend indenting code consistently, it has no influence whatsoever on the way the code executes.

    If the code jumps straight from the Do While line to the MsgBox line, it means that there are no files that conform to the pattern ZataCC Test*.html. So either the path is not correct - look VERY carefully for spelling errors - even an extra or missing space will cause the path not to be recognized - or there are no .html files in the ZataCC Test folder.

  12. #12
    2 Star Lounger
    Join Date
    Dec 2004
    Location
    Stoney Creek, Ontario
    Posts
    196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Defining variable problem re: html (2003)

    Thanks for your patience with this Hans. All is well now. The tip off was in your last post about no html files in the folder. That made me wonder at bit and the problem for me was that the that the Type of all these files is HTML Document. The file extension (after un-hidding them in View) is htm. Lesson learned.

    Thanks again.

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Defining variable problem re: html (2003)

    One more reason for always displaying extensions of known file types. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

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