Hi

I need to turn off the printing of hidden text in my vb6 program so I have inserted options.PrintHiddenText = False after opening the file in VBA. However it gives me an error 438 which I do not seem to be able to circumvent.

The section of the code is as follows:

    msWord.WordBasic.fileopen WordFile1, 0
    If wordrevisions = 0 Then
        msWord.WordBasic.toolsrevisions 0, 0, 0
    Else
        msWord.WordBasic.toolsrevisions 0, 0, 1
    End If
    Err = 0
    ''20140528
    msWord.WordBasic.options.PrintHiddenText = False
    ''20140528 end
    Err = 0
    msWord.WordBasic.fileprint 0, 0, 4, , , , 0, wordcopies, WordPageRange

Dani AI

Generated

Short diagnosis: the 438 ("object doesn't support this property or method") is coming from calling the legacy WordBasic interface for something that belongs to the modern Word object model. The printing flag that controls whether hidden text is printed lives on the Application.Options object, not under the WordBasic command set. Also note the macro posted by toggles view/display of hidden text (ShowHiddenText) — that controls what you see on-screen, not whether hidden text is sent to the printer.

A safe, simple pattern is to use the Word object model: open the document, save the current Options.PrintHiddenText value, set it to False, print the document, and then restore the original value. Example (use a Word reference for early binding if possible):

Dim wApp As Word.Application
Dim prevPrintHidden As Boolean

Set wApp = CreateObject("Word.Application")
wApp.Documents.Open FileName:=WordFile1
prevPrintHidden = wApp.Options.PrintHiddenText
wApp.Options.PrintHiddenText = False
wApp.ActiveDocument.PrintOut Copies:=wordCopies
wApp.Options.PrintHiddenText = prevPrintHidden
wApp.ActiveDocument.Close SaveChanges:=False
wApp.Quit

Troubleshooting notes: (1) If you must keep using WordBasic.fileprint, set the Application.Options flag before calling the fileprint command. (2) Changing Options.PrintHiddenText is application-wide — always save and restore the previous value to avoid side effects for the user. (3) Add a reference to the Microsoft Word Object Library in your VB6 project to get constants and IntelliSense and to avoid late-binding surprises.

On Error GoTo MainStop
If ActiveWindow.View.ShowAll = False Or ActiveWindow.View.ShowHiddenText = False Then
With ActiveWindow
With .View
.ShowHiddenText = True
.ShowAll = True
End With
End With
Else
With ActiveWindow
With .View
.ShowHiddenText = False
.ShowAll = False
End With
End With
End If
MainStop:
If Err.Number <> 0 Then
MsgBox "This macro shows and hides all hidden text, spaces, tabs, paragraph marks etc. First you need to open a document..."
End If

STEPS TO DO:

  1. In the menu bar at the top of your window in Word, click on the Tools menu. Click on Macro, then on Macros in the sub-menu.

  2. The Macros dialog box will open. Type the name "ShowHide" for the macro in the "Macro name:" field.

  3. Click the Create button.

  4. A window titled "Microsoft Visual Basic – Normal – [New Macros (Code)]" will open. In the window that appears, find the line of text that reads: Macro created [Today’s Date] by [Your Name]

  5. Paste the macro lines that you copied in Step 1 into the Visual Basic window, at the spot where the input cursor is blinking.

  6. Save your macro by clicking the Save button (diskette icon) on the toolbar.

  7. Close the whole Visual Basic window. Your macro is now installed.

  8. Add a macro button in your toolbar or in your right-click menu to run the macro.

How to run the macro

Open a document containing hidden text. Click once on the macro button to perform one operation (show or hide) and again to perform the opposite.

Keywords: MS Word spellcheck macro MS Word spell-check macro MS Word macro

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.