0

Is it possible to change a css style through vbscript? The code bellow won't work on windows scripting host:

Dim oIE

Set oIE = CreateObject("InternetExplorer.Application")

oIE.navigate("www.website.com")

Do While oIE.Busy
    WScript.Sleep 100
Loop

oIE.document.getElementById("div-id-here").style.backgroundcolor="#ff0000"
11
  • Just to clarify - you are building this for something that only runs in IE or some embedded IE browser - correct? Commented Nov 4, 2013 at 13:35
  • 1
    Wow, VBScript still exists.....who knew... Commented Nov 4, 2013 at 13:36
  • If the VBScript is like JavaScript... you'll likely need to use the camelCase backgroundColor (capital C) to get this to work in IE. Commented Nov 4, 2013 at 13:36
  • @scunliffe, I think this runs in the windows scripting host thingy.... (whispers) I'm not sure what that is... Commented Nov 4, 2013 at 13:37
  • 1
    @Liam virus writers got to live from something, isn't it? ;) Commented Nov 4, 2013 at 13:42

1 Answer 1

1

It works, but by default the window is hidden so you don't see anything.

To make it appear, add this line:

oIE.Visible = True
Sign up to request clarification or add additional context in comments.

3 Comments

It's good practice to do Dim elem: Set elem = oIE.document.getElementById("div-id-here") and later If Not elem Is Nothing Then ..., since getElementById is not guaranteed to return anything.
@Tom true, that's a different side of the problem so feel free to post it as new answer.
Yeah, not worth the hassle. It was more directed at the OP. Either he makes something of it - or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.