#1
|
||||
|
||||
Macro problems with Word for Mac 2016 16.9.1
I have a free macro from DocTools that I used for years in Word under Windows and Mac, and it suddenly fails under the newest Word for Mac version. The author of DocTools says she works only with Windows (although the macro worked fine on my Mac before). I get an error message almost immediately about "Run-Time Error 4231" and "Command not available." It stops at this line:
"Creation date: " & Format(Date, "MMMM d, yyyy") I can't figure out how to debug this or what's been changed in that newest Word update. I tried turning on macros in Word and that doesn't change the results. Here's the macro: Code:
Sub ExtractCommentsToNewDoc() ' ' ExtractCommentsToNewDoc Macro 'Macro created 2007 by Lene Fredborg, DocTools - www.thedoctools.com 'The macro creates a new document 'and extracts all comments from the active document 'incl. metadata 'Minor adjustments are made to the styles used 'You may need to change the style settings and table layout to fit your needs '========================= Dim oDoc As Document Dim oNewDoc As Document Dim oTable As Table Dim nCount As Long Dim n As Long Dim Title As String Title = "Extract All Comments to New Document" Set oDoc = ActiveDocument nCount = ActiveDocument.Comments.Count If nCount = 0 Then MsgBox "The active document contains no comments.", vbOKOnly, Title GoTo ExitHere Else 'Stop if user does not click Yes If MsgBox("Do you want to extract all comments to a new document?", _ vbYesNo + vbQuestion, Title) <> vbYes Then GoTo ExitHere End If End If Application.ScreenUpdating = False 'Create a new document for the comments, base on Normal.dot Set oNewDoc = Documents.Add 'Set to landscape oNewDoc.PageSetup.Orientation = wdOrientLandscape 'Insert a 4-column table for the comments With oNewDoc .Content = "" Set oTable = .Tables.Add _ (Range:=Selection.Range, _ numrows:=nCount + 1, _ NumColumns:=4) End With 'Insert info in header - change date format as you wish oNewDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = _ "Comments extracted from: " & oDoc.FullName & vbCr & _ "Created by: " & Application.UserName & vbCr & _ "Creation date: " & Format(Date, "MMMM d, yyyy") 'Adjust the Normal style and Header style With oNewDoc.Styles(wdStyleNormal) .Font.Name = "Arial" .Font.Size = 10 .ParagraphFormat.LeftIndent = 0 .ParagraphFormat.SpaceAfter = 6 End With With oNewDoc.Styles(wdStyleHeader) .Font.Size = 8 .ParagraphFormat.SpaceAfter = 0 End With 'Format the table appropriately With oTable .Range.Style = wdStyleNormal .AllowAutoFit = False .PreferredWidthType = wdPreferredWidthPercent .PreferredWidth = 100 .Columns(1).PreferredWidth = 5 .Columns(2).PreferredWidth = 25 .Columns(3).PreferredWidth = 50 .Columns(4).PreferredWidth = 20 .Rows(1).HeadingFormat = True End With 'Insert table headings With oTable.Rows(1) .Range.Font.Bold = True .Cells(1).Range.Text = "Page" .Cells(2).Range.Text = "Comment scope" .Cells(3).Range.Text = "Comment text" .Cells(4).Range.Text = "Author" End With 'Get info from each comment from oDoc and insert in table For n = 1 To nCount With oTable.Rows(n + 1) 'Page number .Cells(1).Range.Text = _ oDoc.Comments(n).Scope.Information(wdActiveEndPageNumber) 'The text marked by the comment .Cells(2).Range.Text = oDoc.Comments(n).Scope 'The comment itself .Cells(3).Range.Text = oDoc.Comments(n).Range.Text 'The comment author .Cells(4).Range.Text = oDoc.Comments(n).Author End With Next n Application.ScreenUpdating = True Application.ScreenRefresh oNewDoc.Activate MsgBox nCount & " comments found. Finished creating comments document.", vbOKOnly, Title ExitHere: Set oDoc = Nothing Set oNewDoc = Nothing Set oTable = Nothing End Sub Last edited by macropod; 02-03-2018 at 12:55 PM. Reason: Added code tags |
#2
|
||||
|
||||
I found that deleting this block allows the macro to run, but there are no column lines and no column titles. So can anyone tell me what's wrong with this block of code?
'Insert info in header - change date format as you wish oNewDoc.Sections(1).Headers(wdHeaderFooterPrimary) .Range.Text = _ "Tracked changes extracted from: " & oDoc.FullName & vbCr & _ "Created by: " & Application.UserName & vbCr & _ "Creation date: " & Format(Date, "MMMM d, yyyy") |
#3
|
||||
|
||||
The problem seems to be "Application.UserName" which when changed to just "UserName" allows the macro to run, but then the field is empty in the header, so I took out the whole block for the header. I read elsewhere that "Author" may work. The header wasn't appearing on the first page, so that was another reason to cut the header contents. And the table's cell lines disappeared with the Word update, and I fixed that by adding .Borders.Enable = True to the block that formats the table.
The problem with the table lines is probably a 16.9.1 issue, because saving as PDF a document with a table seems to screw up the lines, across the board on most files. I've reverted to the pre-16 version of Word. Last edited by JML; 02-04-2018 at 11:08 AM. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Word 2016 Multi-file Macro issues | IneedHelpWithWord | Word VBA | 1 | 08-08-2017 09:29 PM |
Outlook 2016 Search Problems | roblopcpa | Outlook | 3 | 06-28-2017 04:53 AM |
VBA add-in no longer works in Word 2016 - macro error | paulkaye | Word VBA | 6 | 06-13-2017 06:50 AM |
Visio 2016 diagrams embeded in word 2016 not drawing properly | stubbo66 | Visio | 2 | 08-24-2016 05:58 PM |
Excel problems since using Office 365 especially since 2016 | USAOz | Excel | 0 | 11-10-2015 09:06 PM |