Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    2 Star Lounger
    Join Date
    Sep 2001
    Location
    Middelburg, Zeeland, Netherlands
    Posts
    165
    Thanks
    20
    Thanked 2 Times in 2 Posts

    edit cell (2000)

    Hi,
    I want to have a simple macro to change the color in a cell of a table (not a HTML-table that is).
    Lets say it's green and it has to become red.
    Anybody out there to help me?
    TIA George

  2. #2
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: edit cell (2000)

    I don't use macros in FP myself, but FrontPage2000/2002 Macros - Getting Started may give you a leg up.

  3. #3
    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: edit cell (2000)

    When you say it's not an HTML table, what kind of table is it?

    If you are embedding an Excel worksheet, and want to provide HTML controls that interact with the worksheet, you might want to describe the scenario on the Excel board and see if anyone there is familiar with this issue.

  4. #4
    2 Star Lounger
    Join Date
    Sep 2001
    Location
    Middelburg, Zeeland, Netherlands
    Posts
    165
    Thanks
    20
    Thanked 2 Times in 2 Posts

    Re: edit cell (2000)

    Thanx Leif,
    Seen that but that doesn't help.
    I'm looking for specific commands to alter the color of the cell by macro.
    CU, george

  5. #5
    2 Star Lounger
    Join Date
    Sep 2001
    Location
    Middelburg, Zeeland, Netherlands
    Posts
    165
    Thanks
    20
    Thanked 2 Times in 2 Posts

    Re: edit cell (2000)

    Hi jscher2000,
    sorry, but of course it's html-table but it looks like an excel-table.
    It's a vacancy/no vacancy table of which we have to change the color of the cells regularly.
    It's too much of a hassle to do that by hand.
    That's why I want to create several simple macro's to change to red, orange or green and v.v.
    Any ideas?
    TIA
    George

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

    Assign Cell Background-Color with VBA

    This was a tough one. There's only the most indirect way to get to the table cell that contains the insertion point. Please know that I've only done the most limited testing on this, using FrontPage 2002, but it does seem to work:

    Sub CellBGRed()
    Call ChangeCellBGColor("red")
    End Sub

    Sub CellBGGreen()
    Call ChangeCellBGColor("green")
    End Sub

    Sub CellBGOrange()
    Call ChangeCellBGColor("orange")
    End Sub

    Sub ChangeCellBGColor(strColor As String)
    ' Jefferson Scher 23 Nov 2004
    ' Works from the user's insertion point
    ' Should validate the input parameter, but...
    Dim rng As Object
    Set rng = ActiveDocument.Selection.createRange.parentElement
    Do While LCase$(rng.tagName) <> "td"
    Set rng = rng.parentElement
    If LCase$(rng.tagName) = "body" Then
    MsgBox "Not in a table cell!"
    Set rng = Nothing
    Exit Sub
    End If
    Loop
    rng.Style.backgroundColor = strColor
    Set rng = Nothing
    End Sub

    You can pass either a recognized color name or a color number (e.g., #0088FF). Probably the fastest way to access these macros would be to add them to a toolbar. Do they work in FP2000?

  7. #7
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: edit cell (2000)

    Sounds like you should really have this as a little database application, and display the HTML with asp. That way the asp will update the colors automatically.

  8. #8
    2 Star Lounger
    Join Date
    Sep 2001
    Location
    Middelburg, Zeeland, Netherlands
    Posts
    165
    Thanks
    20
    Thanked 2 Times in 2 Posts

    Re: Assign Cell Background-Color with VBA

    Hi Jeff,
    It works!
    I only had to change: Do While LCase$(rng.tagName) <> "td"
    into Do While LCase$(rng.tagName) &lt> "td" for 2000 to work.
    Great and many thanx.
    I would never have been able to write this.
    I couldn't believe there was not a direct way to change this.
    I've done my part in "macro-ing" in Word and Excel, so I thought I do a quicky in FP too.
    Didn't reckon with Bill B. though :-(
    thnx again, George

  9. #9
    2 Star Lounger
    Join Date
    Sep 2001
    Location
    Middelburg, Zeeland, Netherlands
    Posts
    165
    Thanks
    20
    Thanked 2 Times in 2 Posts

    Re: Assign Cell Background-Color with VBA

    By the way, the results you can always find on www.campveersetoren.nl
    Go to hotel, available? And you see part of your work.
    Added grey and blue as well of course.
    George

  10. #10
    2 Star Lounger
    Join Date
    Sep 2001
    Location
    Middelburg, Zeeland, Netherlands
    Posts
    165
    Thanks
    20
    Thanked 2 Times in 2 Posts

    Re: edit cell (2000)

    Drew, thanx for thinking, but Jefferson really helped me out.
    Nice little macro he made.
    George

  11. #11
    2 Star Lounger
    Join Date
    Sep 2001
    Location
    Middelburg, Zeeland, Netherlands
    Posts
    165
    Thanks
    20
    Thanked 2 Times in 2 Posts

    Re: Assign Cell Background-Color with VBA

    Jeff,
    Leif sent me a mail about the difference in the 2 lines.
    I answered:
    Hi,
    I don't know what happened here but I copied 'Do While LCase$(rng.tagName) <> "td" '
    and edited it to ' Do While LCase$(rng.tagName) &lt> "td" '
    While doing this I wondered if anyone would see the change!
    But I guess some script changed both <> and &lt> (whithout the ; ) into <
    Miracles of Window I guess.
    George

  12. #12
    2 Star Lounger
    Join Date
    Sep 2001
    Location
    Middelburg, Zeeland, Netherlands
    Posts
    165
    Thanks
    20
    Thanked 2 Times in 2 Posts

    Re: Assign Cell Background-Color with VBA

    This is weird:
    I write & l t ; > (without the spaces) and during post the scripts of this site change that into <>
    Same with & l t >
    Anyone knows what's going on? It's HTML that's in the way I guess.
    George

  13. #13
    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: Assign Cell Background-Color with VBA

    The lounge software tries to prevent the posting of live code, to prevent scripting attacks. When all else fails, you can export your module to a .bas file, zip it up, and post the zip file. Or open MS Paint, and paste lines of code into a textbox, and then save as GIF or PNG and attach to your post. Many ways to work around this feature. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  14. #14
    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: Assign Cell Background-Color with VBA

    Oh, maybe the problem was with the code copied from the Lounge? If you have trouble copying and pasting "normal text" from the Web into FrontPage or any Office application, try pasting into Notepad first. It will give you the plain text only, and prevent the Office application from interpreting the clipboard contents in ways that were not intended. If you are pasting preformatted text (usually in Courier font), paste into the body of a Word document first, as otherwise you can end up with all code on one line.

  15. #15
    2 Star Lounger
    Join Date
    Sep 2001
    Location
    Middelburg, Zeeland, Netherlands
    Posts
    165
    Thanks
    20
    Thanked 2 Times in 2 Posts

    Re: Assign Cell Background-Color with VBA

    Hi Jeff, did you have a look at the result on the webpage? Neat, right?
    Can I also use this for a range of cells?
    If yes, what do I have to alter?
    TIA, George

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
  •