Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21969

Run-time error '91': Object variable or With block variable not set

$
0
0
I'm trying to learn VB6, and I created a Word 2007 macro using code I copied from a tutorial. When I run the code, I get a VB error message: "Run-time error '91': Object variable or With block variable not set". There had been a With block, so I removed that, but still get the error. Here's the code:

Sub ChangeColor()
'
' ChangeColor Macro
' Macro created Nov. 13, 2012 by Wardo
'

Dim intRed As Integer
Dim intGreen As Integer
Dim intBlue As Integer

intRed = InputBox("Red value? (0-255)")
intGreen = InputBox("Green value? (0-255)")
intBlue = InputBox("Blue value? (0-255)")

ActiveWindow.View = wdWebView

ActiveDocument.Background.Fill.Visible = msoTrue
ActiveDocument.Background.Fill.ForeColor.RGB = RGB(intRed, intGreen, intBlue)

MsgBox "The document's background is now RGB(" & _
intRed & ", " & intGreen & ", " & intBlue & ")."

End Sub


Another web site said objects need to be set, but I'm not sure how to do that, or why the tutorial author didn't do it (tutorial may be outdated?).

Viewing all articles
Browse latest Browse all 21969

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>