Word 2007 VBA can not set options.print... properties

D

Dmitri Karpov

Has anyone else run into this (and found a reason/fix)?
On one of our five test dev machines, Word 2007 has a weird bug.
Start a blank new doc, go into the VBA macro editing area, add the
line:
options.printbackground=false
(on our machine, you can use ANY of the print options for this test -
printcomments, printbackgrounds, printdraft, etc.). they ALL fail...
but the non-print options are fine.)

If I try to run the macro, it breaks on that line with a runtime 4120
error bad parameter.
I've changed it to options.printbackground=true - still no go.
I've tried changing the default printer and restarting word. Still no
go.

Curiously, I can do a:
msgbox options.printbackground
and it will accurately read the value of the printbackground hckecbox
from the word options, advanced, printing section.

so... on this ONE machine, I can READ but not SET the options for
printing programmatically.

Any ideas??? Corrupt install??? Read only xml ini file or some other
obscure weirdness????
Regards.
 
M

MikeG

Hi Dmitri

I've got exactly the same problem on one of our test PCs.
As with you I can read the "options.UpdateFieldsAtPrint" setting but can not
change it without getting the "error 4120 bad parameter".
The same macro runs fine on various other machines using Word 2007.
The only difference I can find with the faulty machine is that it is running
Office 2007 Home and Student (on WinXP) where as the others are running
"full" versions of Office 2007 on either XP or Vista.
What version of Office are you getting the problem with?
 
M

Mary Mc

I, too, have the same problem at one of my clients' offices. Windows XP
Professional, Version 2002, Service Pack 2 and Word 2007 (12.0.4518.1014) MSO
(12.0.4518.1014).

Can't set any of the Options.
.UpdateFieldsAtPrint = True
.UpdateLinksAtPrint = False
.DefaultTray = "Use printer settings"
.PrintBackground = True
.PrintProperties = True
.PrintFieldCodes = True
.PrintComments = True
.PrintHiddenText = True
.PrintDrawingObjects = True
.PrintDraft = False
.PrintReverse = False
.MapPaperSize = True
Get the same error 4120, bad parameter.
I only care about three of them but they all fail.
 
M

Mike Borozdin

We have hit the same issue. Interestingly enough Word 2007 on Vista works
fine and the same interop code works fine on Word 2003/XPSP2.

We are using .NET interop to print word documents in the background.

I am curious if there is a diagnostic dump of an office installation that
can help us compare the installation.
 
R

Russ

Thanks for the feedback.
I posted this question several months ago (under y dmitri karpov account), and
have finally stumbled on the answer.
There is a bug in Word 2007.
If the username and initials fields are not filled in, then for some
inexplicable reason, the VBA code

options.printbackground

will fail to execute with a bad parameter error.

Custom solutions that require this code for printing will fail silently (or
with a bad parameter error).

The solution: have the user put their username and initials in word. Close
word. Try again.

I have reported this bug to Microsoft.

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
T

Tyll

Dmitri,

Also see the thread "Word 2007: Options.ReplaceSelection -> Run-time
error 4120 Bad Parameter" from 10/19/07 which contains more extensive
documentation of the bug and the solution.

Regards, Tyll.
 
H

Hans

Here's a code sample to work around the bug:

Private Sub OfficeUserName()
'User name bug solution
'Validate user name and ask for a correction if needed
Dim MsgText As String
Dim dlgUserInfo As Dialog

Set dlgUserInfo = Dialogs(wdDialogToolsOptionsUserInfo)
MsgText = "An invalid user name was found in Word Options. "
MsgText = MsgText & "Please type in your name!"
Again:
With dlgUserInfo
If Not ValidateUsername(.Name) Then
.Name = InputBox(MsgText, "[My Add-In]", "[Your name]")
If ValidateUsername(.Name) Then
.Execute
Else
GoTo Again
End If
End If
End With
End Sub

Private Function ValidateUsername(OffUserName As String) As Boolean
'A valid user name needs to have at least one character
'which is not a blank space
If Len(OffUserName) >= 1 Then
For I = 1 To Len(OffUserName)
If Mid(OffUserName, I, 1) <> " " Then
ValidateUsername = True
End If
Next
End If
End Function

Regards, Hans
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top