|
|
| Next: Excel Column labels show as numbers |
| Author |
Message |
instant000 External

Since: Oct 26, 2009 Posts: 1
|
Posted: Mon Oct 26, 2009 2:33 pm Post subject: Search and Insert, Search and Replace, Modify Document Margins Archived from groups: microsoft>public>word>formatting>longdocs (more info?) |
|
|
Basically, I have inherited a macro, and I need to modify it.
How do I do the following in a Macro?
Search for specific text?
Example, if I want to locate the string "FINAL INVOICE"
Insert an image before the string?
How do I insert an image, say c:\logo.jpg ?
Is this correct:
' Find Final Invoice and Set font size for header
' Set myRange = ActiveDocument.Content
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=20
' Selection.MoveDown Unit:=wdLine, Count:=20
Selection.Find.Text = "FINAL INVOICE"
While Selection.Find.Execute = True
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.InlineShapes.AddPicture FileName:= _
"M:\logo\logo9.jpg", LinkToFile:=False, SaveWithDocument:= _
True
Selection.MoveDown Unit:=wdLine, Count:=18, Extend:=wdExtend
Selection.Font.Size = 11
Selection.MoveDown Unit:=wdLine, Count:=20
Wend
' Find Commerical Invoice and Set font size for header
' Set myRange = ActiveDocument.Content
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=20
' Selection.MoveDown Unit:=wdLine, Count:=20
Selection.Find.Text = "COMMERCIAL INVOICE"
While Selection.Find.Execute = True
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.InlineShapes.AddPicture FileName:= _
"M:\logo\logo9.jpg", LinkToFile:=False, SaveWithDocument:= _
True
Selection.MoveDown Unit:=wdLine, Count:=18, Extend:=wdExtend
Selection.Font.Size = 11
Selection.MoveDown Unit:=wdLine, Count:=20
Wend
How do I replace text I searched for?
Say, I want to replace the text XXuser01 with an image XXuser01.jpg?
Is this correct:
' Place Paul's signature on the commercial invoice
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.Find.Text = "XXX USER 97"
While Selection.Find.Execute = True
Selection.TypeBackspace
Selection.InlineShapes.AddPicture FileName:= _
"M:\logo\user97.jpg", LinkToFile:=False, SaveWithDocument:= _
True
Wend
How do I modify document margins?
Originally, the document might fit on A4, but I only have 8.5 x 11 to
print it out on. Is there any way to increase the margins inside the
macro?
Is this it?
' Increase Margin's
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(0.15)
.BottomMargin = InchesToPoints(0.1)
.LeftMargin = InchesToPoints(0.25)
.RightMargin = InchesToPoints(0.15)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(8.26)
.PageHeight = InchesToPoints(11.69)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = True
.MirrorMargins = False
.TwoPagesOnOne = False
.GutterPos = wdGutterPosLeft
End With
' Set Font Size
Selection.WholeStory
Selection.Font.Size = 10
--
instant000 |
|
| Back to top |
|
 |
Suzanne S. Barnhill External

Since: Sep 26, 2003 Posts: 24065
|
Posted: Mon Oct 26, 2009 4:34 pm Post subject: Re: Search and Insert, Search and Replace, Modify Document Margins [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
I don't know how to do this with a macro, but I know how to do it without
one. Copy your image to the Clipboard. Then search for "FINAL INVOICE" and
replace with ^c^&. ^c represents the Clipboard contents and ^& represents
the found text.
--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
"instant000" <instant000.52bbc7d.RemoveThis@wordbanter.com> wrote in message
news:instant000.52bbc7d@wordbanter.com...
>
> Basically, I have inherited a macro, and I need to modify it.
>
> How do I do the following in a Macro?
>
> Search for specific text?
> Example, if I want to locate the string "FINAL INVOICE"
> Insert an image before the string?
> How do I insert an image, say c:\logo.jpg ?
>
>
> Is this correct:
>
> ' Find Final Invoice and Set font size for header
> ' Set myRange = ActiveDocument.Content
> Selection.HomeKey Unit:=wdStory
> Selection.MoveDown Unit:=wdLine, Count:=20
> ' Selection.MoveDown Unit:=wdLine, Count:=20
> Selection.Find.Text = "FINAL INVOICE"
> While Selection.Find.Execute = True
>
> Selection.MoveLeft Unit:=wdCharacter, Count:=1
> Selection.MoveUp Unit:=wdLine, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.MoveUp Unit:=wdLine, Count:=1
> Selection.InlineShapes.AddPicture FileName:= _
> "M:\logo\logo9.jpg", LinkToFile:=False, SaveWithDocument:= _
> True
> Selection.MoveDown Unit:=wdLine, Count:=18, Extend:=wdExtend
> Selection.Font.Size = 11
> Selection.MoveDown Unit:=wdLine, Count:=20
> Wend
>
> ' Find Commerical Invoice and Set font size for header
> ' Set myRange = ActiveDocument.Content
> Selection.HomeKey Unit:=wdStory
> Selection.MoveDown Unit:=wdLine, Count:=20
> ' Selection.MoveDown Unit:=wdLine, Count:=20
> Selection.Find.Text = "COMMERCIAL INVOICE"
> While Selection.Find.Execute = True
>
> Selection.MoveLeft Unit:=wdCharacter, Count:=1
> Selection.MoveUp Unit:=wdLine, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.MoveUp Unit:=wdLine, Count:=1
> Selection.InlineShapes.AddPicture FileName:= _
> "M:\logo\logo9.jpg", LinkToFile:=False, SaveWithDocument:= _
> True
> Selection.MoveDown Unit:=wdLine, Count:=18, Extend:=wdExtend
> Selection.Font.Size = 11
> Selection.MoveDown Unit:=wdLine, Count:=20
> Wend
>
>
>
> How do I replace text I searched for?
> Say, I want to replace the text XXuser01 with an image XXuser01.jpg?
>
> Is this correct:
>
> ' Place Paul's signature on the commercial invoice
> Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
> Selection.Find.Text = "XXX USER 97"
> While Selection.Find.Execute = True
> Selection.TypeBackspace
> Selection.InlineShapes.AddPicture FileName:= _
> "M:\logo\user97.jpg", LinkToFile:=False, SaveWithDocument:= _
> True
> Wend
>
> How do I modify document margins?
> Originally, the document might fit on A4, but I only have 8.5 x 11 to
> print it out on. Is there any way to increase the margins inside the
> macro?
>
> Is this it?
> ' Increase Margin's
>
> With ActiveDocument.PageSetup
> LineNumbering.Active = False
> Orientation = wdOrientPortrait
> TopMargin = InchesToPoints(0.15)
> BottomMargin = InchesToPoints(0.1)
> LeftMargin = InchesToPoints(0.25)
> RightMargin = InchesToPoints(0.15)
> Gutter = InchesToPoints(0)
> HeaderDistance = InchesToPoints(0.5)
> FooterDistance = InchesToPoints(0.5)
> PageWidth = InchesToPoints(8.26)
> PageHeight = InchesToPoints(11.69)
> FirstPageTray = wdPrinterDefaultBin
> OtherPagesTray = wdPrinterDefaultBin
> SectionStart = wdSectionNewPage
> OddAndEvenPagesHeaderFooter = False
> DifferentFirstPageHeaderFooter = False
> VerticalAlignment = wdAlignVerticalTop
> SuppressEndnotes = True
> MirrorMargins = False
>
> TwoPagesOnOne = False
> GutterPos = wdGutterPosLeft
> End With
>
> ' Set Font Size
>
> Selection.WholeStory
> Selection.Font.Size = 10
>
>
>
>
> --
> instant000
> |
|
| Back to top |
|
 |
|
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
| |
|
|