Answered by:
Need help with a macro and a question about them on Mac

Question
-
I'm very very new to macros in Word (2011 for Mac), and looking to speed up some processes for voice over scripts that I record. One client in particular (who sends work regularly) gives us Word docs with each screen to be recorded in a table format.
I've found a macro that converts the table to text (but puts "," at the end of some of where the columns were !):
Sub AllTablestoText()
For Each aTable In ActiveDocument.Tables
aTable.ConvertToText wdSeparateByTabs, True
Next aTable
End Sub '
and now I'm wanting to extend the functionality by:* Moving the left and right margins out to 1.5cm
* Left justifying all the text
* Marking the text as 11pt Arial
* Line spacing at 1.5 lines with 0pt above/below.
I'm sure it can be done, but I just don't have the knowhow with Visual Basic/Macros.
If you can help, it'd be much appreciated !
Also, is there such a thing as a keyboard shortcut for Macros in MS Word 2011 for Mac anymore ?Friday, October 5, 2012 11:37 PM
Answers
-
If you create a Style with the required formatting beforehand, you could use a macro like:
Sub AllTablesToText1()
Application.ScreenUpdating = False
Dim i As Long, Rng As Range
With ActiveDocument
For i = .Tables.Count To 1 Step -1
Set Rng = Tables(i).ConvertToText(wdSeparateByTabs, True)
Rng.Style = "MyStyle"
Next
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End Subwhere "MyStyle" is the Style name.
Failing that, you can have the macro create the Style:
Sub AllTablesToText2()
Application.ScreenUpdating = False
Dim i As Long, Rng As Range, StrSty As String
StrSty = "MyStyle"
With ActiveDocument
On Error Resume Next
.Styles.Add Name:=StrSty, Type:=wdStyleTypeParagraph
On Error GoTo 0
With .Styles("MyStyle")
With .Font
.Name = "Arial"
.Size = 11
End With
With .ParagraphFormat
.LeftIndent = CentimetersToPoints(1.5)
.RightIndent = CentimetersToPoints(1.5)
.Alignment = wdAlignParagraphLeft
.Space15
.SpaceBefore = 0
.SpaceAfter = 0
End With
End With
For i = .Tables.Count To 1 Step -1
Set Rng = Tables(i).ConvertToText(wdSeparateByTabs, True)
Rng.Style = StrSty
Next
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End SubThe least desirable (and slowest) approach is to simply override whatever Styles are already present:
Sub AllTablesToText3()
Application.ScreenUpdating = False
Dim i As Long, Rng As Range
With ActiveDocument
For i = .Tables.Count To 1 Step -1
Set Rng = Tables(i).ConvertToText(wdSeparateByTabs, True)
With Rng
With .Font
.Name = "Arial"
.Size = 11
End With
With .ParagraphFormat
.LeftIndent = CentimetersToPoints(1.5)
.RightIndent = CentimetersToPoints(1.5)
.Alignment = wdAlignParagraphLeft
.Space15
.SpaceBefore = 0
.SpaceAfter = 0
End With
End With
Next
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End SubThere's nothing in the code you're using that would explain why a '!' might change to ','.
Cheers
Paul Edstein
[MS MVP - Word]- Marked as answer by Max Meng Friday, October 12, 2012 9:34 AM
Sunday, October 7, 2012 5:18 AM
All replies
-
If you create a Style with the required formatting beforehand, you could use a macro like:
Sub AllTablesToText1()
Application.ScreenUpdating = False
Dim i As Long, Rng As Range
With ActiveDocument
For i = .Tables.Count To 1 Step -1
Set Rng = Tables(i).ConvertToText(wdSeparateByTabs, True)
Rng.Style = "MyStyle"
Next
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End Subwhere "MyStyle" is the Style name.
Failing that, you can have the macro create the Style:
Sub AllTablesToText2()
Application.ScreenUpdating = False
Dim i As Long, Rng As Range, StrSty As String
StrSty = "MyStyle"
With ActiveDocument
On Error Resume Next
.Styles.Add Name:=StrSty, Type:=wdStyleTypeParagraph
On Error GoTo 0
With .Styles("MyStyle")
With .Font
.Name = "Arial"
.Size = 11
End With
With .ParagraphFormat
.LeftIndent = CentimetersToPoints(1.5)
.RightIndent = CentimetersToPoints(1.5)
.Alignment = wdAlignParagraphLeft
.Space15
.SpaceBefore = 0
.SpaceAfter = 0
End With
End With
For i = .Tables.Count To 1 Step -1
Set Rng = Tables(i).ConvertToText(wdSeparateByTabs, True)
Rng.Style = StrSty
Next
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End SubThe least desirable (and slowest) approach is to simply override whatever Styles are already present:
Sub AllTablesToText3()
Application.ScreenUpdating = False
Dim i As Long, Rng As Range
With ActiveDocument
For i = .Tables.Count To 1 Step -1
Set Rng = Tables(i).ConvertToText(wdSeparateByTabs, True)
With Rng
With .Font
.Name = "Arial"
.Size = 11
End With
With .ParagraphFormat
.LeftIndent = CentimetersToPoints(1.5)
.RightIndent = CentimetersToPoints(1.5)
.Alignment = wdAlignParagraphLeft
.Space15
.SpaceBefore = 0
.SpaceAfter = 0
End With
End With
Next
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End SubThere's nothing in the code you're using that would explain why a '!' might change to ','.
Cheers
Paul Edstein
[MS MVP - Word]- Marked as answer by Max Meng Friday, October 12, 2012 9:34 AM
Sunday, October 7, 2012 5:18 AM -
> Also, is there such a thing as a keyboard shortcut for Macros in MS Word 2011 for Mac anymore ?
Option-F8 to get to the list of macros
Option-F11 to get to the VB Editor
(you may need fn-option-F8 etc. depending on your keyboard and System Preferences)Or did you mean something else?
Peter Jamieson
Tuesday, October 16, 2012 4:07 PM -
> Also, is there such a thing as a keyboard shortcut for Macros in MS Word 2011 for Mac anymore ?
Option-F8 to get to the macro list
Option-F11 to get tot he VB editor
(or fn-Option-F8 etc. depending on your keyboard and System Preferences)Or did you mean something else?
Peter Jamieson
Tuesday, October 16, 2012 4:08 PM