Log in

View Full Version : Word 2010 Status Bar Problem



gmaxey
02-09-2013, 08:48 AM
I have a template dotm file (uploaded a a docm that hopefully you can rename with a .dotm extension) that illustrates a problem that I've encountered with the StatusBar in Word 2010. The problem does not occur with the same code used in a .dot file with Word 2003.

The template is used as a Global Add-In and it contains data required for the add-in to work. So when the add-in is loaded it is opened as a document so Word can extract the data then closed.

All that works well. However if the add-in is loaded on startup or loaded manually after first starting Word then after the add-in loads, the StatusBar is displaying the add-in file name. This display appears to be "stuck" as the status bar does not display document statistics (e.g., Page No., Line No. Words, etc). as the user types.

Oddly enough, I can get it out of this stuck situation by typing in a URL e.g, www.google.com (http://www.google.com) and then mousing over the URL. After this all seems well.

I've managed a fix shown in the comments lines below. Still I would like to understand why this occurs and if there is generally a better way to fix or avoid the situation altogether. Thanks.


Sub AutoExec()
LoadAddInData
lbl_Exit:
Exit Sub
End Sub
Sub LoadAddInData()
Dim oTmp As Template, oDoc As Word.Document, oTbl As Word.Table
Dim lngIndex As Long, arrData() As String
Dim bClose As Boolean

bClose = True
Set oTmp = ThisDocument.AttachedTemplate
'This keeps the Add-In from crashing Word if loaded on start-up. Better way?
If Documents.Count = 0 Then Documents.Add
'Get access to template table.
If Not ActiveDocument.Name = oTmp.Name Then
Application.ScreenUpdating = False
Set oDoc = oTmp.OpenAsDocument
Else
Set oDoc = ActiveDocument
bClose = False
End If
Set oTbl = oDoc.Tables(1)
'Load currency data from template table.
ReDim arrData(oTbl.Rows.Count - 2, 2)
For lngIndex = 2 To oTbl.Rows.Count
arrData(lngIndex - 2, 0) = GetCellText(oTbl.Rows(lngIndex).Cells(1))
arrData(lngIndex - 2, 1) = GetCellText(oTbl.Rows(lngIndex).Cells(2))
arrData(lngIndex - 2, 2) = GetCellText(oTbl.Rows(lngIndex).Cells(3))
Next lngIndex
If bClose Then oDoc.Close wdDoNotSaveChanges
'Uncomment this code to fix.
'If Documents.Count = 1 Then
'Documents.Add
'Documents(1).Close wdDoNotSaveChanges
'End If
Set oTbl = Nothing
Set oDoc = Nothing
Set oTmp = Nothing
Application.ScreenUpdating = True
Exit Sub
End Sub
Function GetCellText(ByRef oCell As Word.Cell) As String
GetCellText = Left(oCell.Range.Text, Len(oCell.Range.Text) - 2)
lbl_Exit:
Exit Function
End Function

fumei
02-09-2013, 01:41 PM
Well it is interesting that it does not do this in 2003. Just shows how much 2010 sucks......just kidding.

Your data does not seem all that much (or am I missing something). Why not just hard code it in the add-in. It seems a bit inefficient to both load the file as an add-in AND load it as a document file.

gmaxey
02-09-2013, 08:08 PM
Gerry,

Well the file uploaded was must to demonstrate the issue. The actual Add-In will contain a table of 15 to 60 rows and I did is this way to the end user could open the add-in template as a file and directly edit the table data.

gmaxey
02-10-2013, 11:51 AM
Well thanks to private advice from Jason (aka Frosty) the whole issue is resolved by using "ThisDocument" as follows:


Sub AutoExec()
LoadAddInData
lbl_Exit: Exit Sub
End Sub
Sub LoadAddInData()
Dim oTbl As Word.Table
Dim lngIndex As Long, arrData() As String

Set oTbl = ThisDocument.Tables(1)
ReDim arrData(oTbl.Rows.Count - 2, 2)
For lngIndex = 2 To oTbl.Rows.Count
arrData(lngIndex - 2, 0) = GetCellText(oTbl.Rows(lngIndex).Cells(1))
arrData(lngIndex - 2, 1) = GetCellText(oTbl.Rows(lngIndex).Cells(2))
arrData(lngIndex - 2, 2) = GetCellText(oTbl.Rows(lngIndex).Cells(3))
Next lngIndex
Set oTbl = Nothing
End Sub
Function GetCellText(ByRef oCell As Word.Cell) As String GetCellText = Left(oCell.Range.Text, Len(oCell.Range.Text) - 2) lbl_Exit: Exit Function End Function