"Won't execute code in break mode?

Anonymous
2015-12-17T23:32:12+00:00

I am having a heck of a time trying to get a Word file to behave.   I wrote a table in Excel and pasted it into a new, blank Word file.   Now Word won't let me format the table.   I want the table to fit the size of my paper, and I want to adjust the column widths to a more visually pleasing format.   Instead Word insists on using the automatic formats; I can't turn them off in "Table Properties."  "Auto Fit" won't work; the table remains 23 inches long (in landscape mode.)   I try to drag the gridlines in the table; when I release them, they snap back to where they were.   I try to quit; a dialog box appears and says that Word won't execute an unspecified code in break mode (whatever that is.)   I have to force-quit Word to get rid of the dialog box.   

When I reopen the file, I get this dialog box:

Word gives the following diagnostic report.  Does this report mean anything to anyone here?  TIA

Option Explicit

Sub AutoExec()

Dim docReady As Integer

    docReady = Application.Documents.Count ' See if we have a document yet

If docReady < 1 Then ' Wait 1 sec then call itself recursively

        Application.OnTime Now + TimeValue("00:00:01"), "AutoExec"

End If

    ReadView ' Checks for a stored view, and restores it if there is one

If ActiveDocument.Bookmarks.Exists("macroMarkHere") Then gotoSpot ' restores cursor location

End Sub

Sub AutoOpen()

    ReadView ' Checks for a stored view, and restores it if there is one

If ActiveDocument.Bookmarks.Exists("macroMarkHere") Then gotoSpot '  restores cursor location

End Sub

Sub AutoNew()

    ReadView ' Checks for a stored view, and restores it if there is one

End Sub

Sub AutoClose()

    WriteView        ' Writes the view into the document

End Sub

Sub FileSave()

'  This macro intercepts FileSave commands and calls WriteView

'  Because Mac Word has no document events

' Macro written 22 Nov 2010 by John McGhie

' (c) Copyright McGhie Information Engineering Pty Ltd, November 2010

With ActiveDocument

        WriteView        ' Writes the view into the document

If .Path = .Name Then ' Document has never been saved

             Dialogs(wdDialogFileSaveAs).Show

Else

            .Save

End If

End With

End Sub

Function markSpot()

    Selection.Collapse

    Selection.Bookmarks.add Name:="macroMarkHere", Range:=Selection.Range

End Function

Function gotoSpot()

Selection.GoTo What:=wdGoToBookmark, Name:="macroMarkHere"

End Function

Function CheckVersion()

Dim appVersion As Integer

appVersion = Val(Left(Application.Version, 2))

If System.OperatingSystem = "Macintosh" And Application.Name = "Microsoft Word" And appVersion > 13 Then

'       It 's OK

    CheckVersion = True

Else

    MsgBox "Sorry, the Restore View Macros cannot run here.  They require Microsoft Word at version 2011 or better.", vbCritical + vbOKOnly, "Restore View Macros"

End

End If

End Function

Sub WriteView()

' Writes current document display properties into the document on save

' Macro written 22 Nov 2010 by John McGhie

' (c) Copyright McGhie Information Engineering Pty Ltd, November 2010

Dim aDoc As Document

If CheckVersion = True Then ' We're not in an old version

If Application.Documents.Count > 0 Then  ' The user can leave us with no documents

Set aDoc = ActiveDocument

With aDoc

If .Content.End > 1 Then ' Don't bother if document has no content

If Not .ReadOnly Then '  or document is read-only

                    markSpot                 '  marks cursor location

With Application.ActiveWindow

' Window state will be 0 if it's Normal, add 1 so we can tell if we have one

                        CSVars aDoc, "WindowState", .WindowState + 1

                        CSVars aDoc, "WindowTop", .Top

                        CSVars aDoc, "WindowLeft", .Left

                        CSVars aDoc, "WindowWidth", .Width

                        CSVars aDoc, "WindowHeight", .Height

                        CSVars aDoc, "WindowZoom", .View.Zoom

End With ' ActiveWindow

End If ' Read-only

End If ' No content

End With ' aDoc

End If ' No documents

End If

End Sub

Sub ReadView()

' Reads document display properties stored in the document and sets the view

' Macro written 22 Nov 2010 by John McGhie

' (c) Copyright McGhie Information Engineering Pty Ltd, November 2010

Dim aDoc As Document

Dim varWindowState As Integer

Dim intTop As Long, intLeft As Long, intWidth As Long, intHeight As Long, intZoom As Long

If CheckVersion = True Then

If Application.Documents.Count = 0 Then End

If ActiveDocument.ReadOnly = False Then ' The user can leave us with no documents, or a read-only document

Set aDoc = ActiveDocument ' The one we just opened

        varWindowState = ReadVars(aDoc, "WindowState") ' Read stored window state

' We add 1 to varWindowState when storing, because it won't be returned if it's 0

If varWindowState = 1 Then ' if not, the other parameters can have no effect

            aDoc.ActiveWindow.WindowState = wdWindowStateNormal ' neither maximised nor minimised

            intTop = ReadVars(aDoc, "WindowTop") ' Read stored properties if they exist

            intLeft = ReadVars(aDoc, "WindowLeft")

            intWidth = ReadVars(aDoc, "WindowWidth")

            intHeight = ReadVars(aDoc, "WindowHeight")

            intZoom = ReadVars(aDoc, "WindowZoom")

' The stored properties are in points: If too big, set to the current maximum

If intLeft > Application.UsableWidth Then intLeft = 0 ' Prevents document opening off screen

If intWidth > Application.UsableWidth Then intWidth = Application.UsableWidth

If intHeight > Application.UsableHeight Then intWidth = Application.UsableHeight

With aDoc.ActiveWindow

' If the properties were not stored in the document, they will come back as zero

If intTop > 0 Then .Top = intTop

If intLeft > 0 Then .Left = intLeft

If intWidth > 0 Then .Width = intWidth

If intHeight > 0 Then .Height = intHeight

If intZoom > 0 Then .View.Zoom = intZoom

End With

End If

End If

End If

End Sub

Function CSVars(aDoc As Document, variableName As String, varValue As Variant)

' Tests for the named variable, creates it if needed, then sets it

' Macro written 22 Nov 2010 by John McGhie

' (c) Copyright McGhie Information Engineering Pty Ltd, November 2010

Dim aVar As Variable

With aDoc

For Each aVar In aDoc.Variables

If aVar.Name = variableName Then

            aVar.Value = varValue

Exit Function

End If

Next ' aVar

    aDoc.Variables.add Name:=variableName, Value:=varValue

End With

End Function

Function ReadVars(aDoc As Document, variableName As String)

' Returns variable if it exists

' Macro written 22 Nov 2010 by John McGhie

' (c) Copyright McGhie Information Engineering Pty Ltd, November 2010

Dim aVar As Variable

With aDoc

For Each aVar In aDoc.Variables

If aVar.Name = variableName Then

            ReadVars = aVar.Value

Exit Function

End If

Next ' aVar

End With

End Function

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. John Korchok 224K Reputation points Volunteer Moderator
    2015-12-18T00:29:36+00:00

    That's a macro, not a diagnostic report. Since John McGhie answers question on this forum regularly, he'll be able to comment on it.

    As for your original issue about pasting an Excel file into Word, there are several paste formats available and one of them will probably come closer to meeting your requirements. Try Edit>Paste Special to access these. Some of them are more editable than others, but none are a true Word table. Unfortunately, the default HTML paste format, which creates a true table in Word 2011 only create a series of numbers with tabs between them, exactly the same as the Formatted Text (RTF) format.

    As an alternative, try creating a real Word table, then select a row and paste using the Unformatted Text option. You Excel content is flowed into the cells and you can apply all the Word formatting commands you want.

    0 comments No comments
  2. Anonymous
    2015-12-18T14:52:13+00:00

    As luck would have it, before I posted my question here, I closed the Word file for about the third or fourth time.   After I posted my question here, I went reopened the file again, and this time Word responded to my commands.

    Maybe Word knew that I was publicly complaining about it and decided to shape up and act right.

    0 comments No comments
  3. Anonymous
    2015-12-18T15:45:09+00:00

    Often times Word stays in memory, or at least the startup kernel of it, even after you've asked it to quit.

    You really have to pay close attention to the dot over the Word icon in your dock. If there is a dot showing then Word is still in memory. Sometimes it takes force quitting, which you do from the Apple icon on the menu bar.

    The ability to get Word out of memory has gotten much worse with Office 2016 for the Mac.

    0 comments No comments