Help finishing a Macro

D

Dennis

Hi all..

This is what I have that works so far using record macro..

Sub CPYSTMT()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "XX/XX"
.Replacement.Text = "WFL/ME"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveWindow.ActivePane.VerticalPercentScrolled = 11
ActiveWindow.ActivePane.VerticalPercentScrolled = 6
Selection.WholeStory
Selection.Copy
End Sub

This is the text in the doc that I would like to stay constant after I
complete my macro…

COPY (WHITE)XX/XX AS (BLUE)XX/XX, (WHITE)XX/XX AS (GOLD)XX/XX, (WHITE)XX/XX AS
(SILVER)XX/XX, (WHITE)XX/XX AS (JADE)XX/XX, (WHITE)XX/XX AS (TAN)XX/XX,
(WHITE)XX/XX AS (DIAMOND)XX/XX, (WHITE)XX/XX AS (PURPLE)XX/XX FROM DISK(PACK)
TO DISK(PACK)

This is what I would like to accomplish…

Replace all the XX/XX using a pop-up box that I would enter the
Replacement.Text = value. This will always be different, not always 'WFL/ME.

Copy the entire doc to clipboard.

Close the doc without saving the changes and without having to manually hit
the 'NO' to 'Do you want to save the changes' box.

Any help would be appreciated.

Thanx, Dennis
===================
 
H

Helmut Weber

Hi Dennis,
I think, this needs further clarification.
Anyway, if You want to define replacement.text before
starting the macro, an inputbox might help. The result
of the inputbox, like aStr$ = inputbox("Question")
would then replace the replacement.text by
..replacement.text = astr$.
To prevent word from asking you whether you want to
save or not, you may use:
activedocument.saved = true
activedocument.close
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, XP, NT4.0, W98
 
M

Mark Tangard

Dennis,

Place this before your code:

Dim x As String
x = InputBox("Enter the replacement text.")
If Trim(x)="" Then Exit Sub

Change the .Replacement.Text line to read:

.Replacement.Text = x

Place this after your code:

ActiveDocument.Close 0

That's all you need. However, if you'll be doing this many
times, you might simplify the approach for the user by having
the macro relieve some of the tedium. For example, if the
replacement text is always going to be in caps, I'd release
the user's obligation to handle that by using this instead:

.Replacement.Text = UCase(x)

And if the replacement text will always be characters, then a
slash, then characters, you could give the user the option of
foregoing the slash and just separating the two parts with a
space, by putting this after the first block of code above:

If InStr(x, " ") > 0 Then
x = Left(x,Instr(x," ")-1) & "/" & Mid$(x,InStr(x," ")+1,99)
End If

Hope this helps a little.
 
M

Mark Tangard

Sure. The -1 is there because you want the left portion to
be the characters from the beginning of the string to the
position BEFORE the position of the space; otherwise the
left portion would include a traililng space so you'd get
something like "WFL /ME" which isn't what you want.

And the 99 just means throgh the end of the string, assuming
of course that it's unlikely to be more than 99 characters.
You'll often see 99 (or 999, etc.) used in a mid$ function
when it's not necessary to know how long the string is but
you do you know you want the entire remainder of the string
no matter how long it is. The function evaluates the same
either way. That is, mid$("abcd",3,2) and mid$("abcd",3,99)
both yield "cd". It just eliminates the needless effort of
computing the position of the end of the string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top