I'll pay $5 to have answered the "VBA Question..." post above.

H

HiThere

See the post above entitled "VBA Question: Edited slides pasted into Word
doc are not saved" on 12/6/05.
 
H

Helmut Weber

Hi,

if I create a powerpoint object the way you do,
then the title bar tells me, here with my german version:
"Microsoft Powerpoint - [Folie in test-01.doc]"
which could be in English:
"Microsoft Powerpoint - [Slide in test-01.doc]".

My assumption is, that this isn't a valid name for a ppt-file.
There should a saveas-dialog pop up, but obviously doesn't.

Create a name and use:
objPPT.ActivePresentation.Save As "c:\test\ppt\test01.ppt".

By the way, I think you would have got an answer
to your first posting at once, if you had removed redundant
lines from the code you had posted,
such as the inputboxes and all of the find and replace thing.

As for the five dollars, drink a beer to my health,
preferable one from the location mentioned in my signature.
 
H

HiThere

Guten Tag Helmut, und danke!
Create a name and use:
objPPT.ActivePresentation.Save As "c:\test\ppt\test01.ppt".

However, I don't want to save the slide as a separate .ppt file, I want the
script to edit the slide pasted into the Word doc as it is and *where* it is
(in the Word doc). So, no fabulous $5 dollar prize for you... :-(

Nonetheless, I'll still happily order a Bavarian beer this weekend and drink
to your health :)
 
H

Helmut Weber

Hi there,

it seems, if you save the word activedocument in between,
the changes in the slide will stay.

[...]
[...]
[...]
Next objShape

ActiveDocument.Save
objPPT.ActivePresentation.Saved = True
objPPT.ActivePresentation.Close
objPPT.Quit


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

HiThere

ActiveDocument.Save
objPPT.ActivePresentation.Saved = True
objPPT.ActivePresentation.Close


This works!!!! Thank You! :)

I will post the final version of the macro here soon, but in the meantime I
need a PayPal address to send $5 to. Is your "red.sys" address capable of
receiving PayPal payments? If you don't want it yourself, then please give
me an address to a charity or something.

Also, you might be happy to know that the completed macro will save one of
my overworked co-workers MANY hours of boring labor while she updates slides
in Word docs...consider yourself silently thanked by her too! :)
 
G

Greg Maxey

I have deleted the origin of this thread, but I am a charitable minded
person. My PayPal address is (e-mail address removed) ;-)
 
H

HiThere

I have deleted the origin of this thread, but I am a charitable minded
person. My PayPal address is (e-mail address removed) ;-)

What does that mean? Helmut, the guy who provided the solution, won't see
my reply?
 
G

Greg Maxey

It was an attempt at light hearted humor. I don't know if Helmut will see
your reply or not. It is posted and if he looks he will see it. He has
already told you:

"As for the five dollars, drink a beer to my health, preferable one from the
location mentioned in my signature."

That means get on a plane and fly to Bavaria. When you get there, drink
bear until your five dollars runs out and Helmut will feel fully compensated
;-)
 
H

Helmut Weber

Hi everybody,
It was an attempt at light hearted humor.

A fully successful attempt! LOL

No, I don't have a paypal address.

Do as Greg suggested! ;-)

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

HiThere

It was an attempt at light hearted humor.
No, I don't have a paypal address.
Do as Greg suggested! ;-)

Well, I do indeed think Greg is a charitable-minded person, and he did give
me his PayPal address, so maybe Helmut's reward could be handled by a
trusted third party...

:)
 
H

HiThere

Here is version 1.0 of the completed macro. If I can get it to run faster
or more cleanly, I'll post the update too. Cheers!



Sub ReplaceInSlides()
'
****************************************************************************
' Version: 1.0, Date: 13.Dec.2005
' This macro will perform a search-and-replace within the bodies of
PowerPoint
' slides that have been pasted into a Word document. This macro should
be run
' from within the Word document, not the PowerPoint presentation. The
macro
' will pop up dialog boxes asking for the text to be found and the text
to
' replace it with. PowerPoint must be installed locally too, and slides
will
' be temporarily opened in PowerPoint as they are edited from the Word
doc.
' The macro is unavoidably very slow. Don't interact with PowerPoint or
Word
' while the macro is running.
'
****************************************************************************
Dim strFind, strReplaceWith, strMessage, strTitle As String
Dim intCount, i As Integer

Dim objPPT As PowerPoint.Application
Dim objSlide As PowerPoint.Slide
Dim objShape As PowerPoint.Shape
Dim objTextRange, objTextRangeFound As PowerPoint.TextRange

strMessage = "Enter the text you wish to find in the slides pasted into
this Word document and have replaced with something else. (Make sure to
back up your Word document first. Close any currently-open PowerPoint
slides.)"
strTitle = "Find What?"
strFind = InputBox(strMessage, strTitle)

strMessage = "Now enter what you wish to replace that text with."
strTitle = "Replace With?"
strReplaceWith = InputBox(strMessage, strTitle)

intCount = ActiveDocument.InlineShapes.Count

If intCount > 0 Then
Set objPPT = New PowerPoint.Application
objPPT.Visible = True

For i = 1 To intCount
If Left(ActiveDocument.InlineShapes.Item(i).OLEFormat.ProgID,
16) = "PowerPoint.Slide" Then
ActiveDocument.InlineShapes(i).OLEFormat.DoVerb
wdOLEVerbOpen

Set objSlide = objPPT.ActivePresentation.Slides(1)

For Each objShape In objSlide.Shapes
If objShape.HasTextFrame Then
Set objTextRange = objShape.TextFrame.TextRange
Set objTextRangeFound =
objTextRange.Replace(FindWhat:=strFind, Replacewhat:=strReplaceWith,
WholeWords:=False)

Do While Not objTextRangeFound Is Nothing
Set objTextRange =
objTextRange.Characters(objTextRangeFound.Start + objTextRangeFound.Length,
objTextRange.Length)
Set objTextRangeFound =
objTextRange.Replace(FindWhat:=strFind, Replacewhat:=strReplaceWith,
WholeWords:=False)
Loop
End If
Next objShape

'Saving is required to force changes to be saved to the Word
doc.
'This is why the macro runs so slowly...
ActiveDocument.Save

objPPT.ActivePresentation.Saved = True
objPPT.ActivePresentation.Close
End If
Next

objPPT.Quit

Else
MsgBox "Could not find any slides in the Word document."
End If

End Sub
 
W

Word Heretic

G'day "HiThere" <[email protected]>,

<SHUDDERS>

Right - this is EXACTLY why I COMPLAIN about the multiple DIM
statement. All the MVPs went "Who the frip cares, you're on drugs' and
here it is again.

To quote myself "It introduces it's own error type, so avoid it." I
sell a book on optimising VBA with a whole bunch of stuff.
Dim strFind, strReplaceWith, strMessage, strTitle As String

MATE - this is the equivalent of
Dim strFind as variant
Dim strReplaceWith as variant
Dim strMessage as variant
Dim strTitle As String


THIS IS NOT WHAT YOU WANTED!!!!! Stop trying to be 'memory efficient',
spell it out longhand, one variable per line, and then comment them
where neccesary. You are only causing yourself grief. Yes, these
variants ARE SLOWING YOUR CODE DOWN.
Dim strFind as String, strReplaceWith as String, strMessage as String, strTitle As String

Is the proper way to code that stupid long line, so hell man, an extra
dim (tokenised) is NOT going to make any damn difference.
Additionally, if you start using custom objects and that line fails,
you wont know which object caused the fail!


Next, your re-use of StrMsg. Dude, lets make it translation friendly
here please. Again, you are achieving NOTHING over a

Msgbox "Whatever the hell"....

Public Sub Whatever()

Const msgFindText as String = "....
Const msgReplaceText as String = "...


This is known as Internationalisation.


Use for each rather than for by.

Set your contexts so you can re-use the current object in context. You
do this with the With statement.

After a good find, collapse your range to its end and extend it to end
of block.

Finally, and most importantly, it is the PP that must be saved, not
the host doc (forcing the client save as well).

Do all this and be amazed at the speed increase!

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


HiThere reckoned:
 
J

Jonathan West

Steve,

I don't remember any such past discussion regarding multiple DIM statements,
and for the record, had I been involved in such a discussion I would have
agreed with you. Moreover, the Word MVP site has an article on precisely
this topic

Why variables should be declared properly
http://www.word.mvps.org/FAQs/MacrosVBA/DeclareVariables.htm


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
W

Word Heretic

G'day "Jonathan West" <[email protected]>,

Twas a year ago, and verily, you were one of my few supporters :)

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Jonathan West reckoned:
 
K

Karl E. Peterson

You must've been battling trolls, for I can't even begin to imagine the
counter-argument that isn't more than sheer nonsense.
 

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