#1   Report Post  
GregR
 
Posts: n/a
Default Macro Syntax

I am looking for the macro syntax to do the following: I am pasting a
recipe from the web to Word. After pasting I want to select the whole
document and format it to my style of "Recipe Format". Then select any
line that has a colon at the end and format this line to my style
"Recipe SubHead", and the remove the colon. Then move to the beginning
of the document and format this line to my style "Recipe Header".
Finally replace any fractions with the superscript/subscript format. TIA

  #2   Report Post  
Greg
 
Posts: n/a
Default

Greg,

You aren't asking for much are you :-)

First, text pasted from the web can be full of nasty formatting that
should first be cleaned up. See:

http://gregmaxey.mvps.org/Clean_Up_Text.htm

Second, the superscript fractions that Word automatically generates for
1/3, 1/2, 3/4 etc. are a special and limited set. However you can get
a close approximation with a macro provided by fellow MVP Graham Mayor.

After you get your text cleaned up, give this a try. Change the style
names to yours.

Sub Test()
Dim myRange As Range
Dim oPara As Paragraph


Set myRange = ActiveDocument.Range
myRange.Style = "Heading 1"
For Each oPara In ActiveDocument.Paragraphs
If oPara.Range.Characters.Last.Previous = ":" Then
oPara.Style = "Heading 2"
oPara.Range.Characters.Last.Previous.Delete
End If
Next
myRange.Paragraphs(1).Style = "Title"
With myRange.Find
.Text = "[0-9]{1,}/[0-9]{1,}"
.MatchWildcards = True
While .Execute
FmtFraction myRange
myRange.Collapse Direction:=wdCollapseEnd
Wend
End With
End Sub
Sub FmtFraction(myRange As Range)
Dim OrigFrac As String
Dim Numerator As String, Denominator As String
Dim NewSlashChar As String
Dim SlashPos As Integer

NewSlashChar = ChrW(&H2044)
OrigFrac = myRange
SlashPos = InStr(OrigFrac, "/")
Numerator = Left(OrigFrac, SlashPos - 1)
Denominator = Right(OrigFrac, Len(OrigFrac) - SlashPos)
myRange.Select
Selection.Font.Superscript = True
Selection.TypeText Text:=Numerator
Selection.Font.Superscript = False
Selection.TypeText Text:=NewSlashChar
Selection.Font.Subscript = True
Selection.TypeText Text:=Denominator
Selection.Font.Subscript = False
End Sub

  #3   Report Post  
GregR
 
Posts: n/a
Default

Greg thank you very much. Maybe it was the first name that caught your
eye.

Greg

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Table in a Form HiDbLevel Tables 12 February 27th 06 12:59 PM
Possible bug when recording a Word Macro Raven95 Microsoft Word Help 4 April 30th 05 09:49 PM
Running document macro from server Intravler New Users 0 March 4th 05 04:33 AM
Save As is not working due to macro security settings Craig Meritz Microsoft Word Help 1 December 16th 04 03:53 AM
2000 to 2002 macro and "Could not open macro storage" Art Farrell Mailmerge 1 December 6th 04 12:40 PM


All times are GMT +1. The time now is 11:03 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"