A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Formatting Long Documents
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Search and Insert, Search and Replace, Modify Document Margins



 
 
Thread Tools Display Modes
  #1  
Old October 26th, 2009, 03:33 PM posted to microsoft.public.word.formatting.longdocs
instant000
external usenet poster
 
Posts: 1
Default Search and Insert, Search and Replace, Modify Document Margins


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
  #2  
Old October 26th, 2009, 10:34 PM posted to microsoft.public.word.formatting.longdocs
Suzanne S. Barnhill
external usenet poster
 
Posts: 31,786
Default Search and Insert, Search and Replace, Modify Document Margins

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" wrote in message
...

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


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:42 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.