Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
HiThere - 08 Dec 2005 20:39 GMT
See the post above entitled "VBA Question: Edited slides pasted into Word
doc are not saved" on 12/6/05.
Helmut Weber - 09 Dec 2005 09:08 GMT
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.

--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
HiThere - 09 Dec 2005 15:40 GMT
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  :-)
Helmut Weber - 09 Dec 2005 20:04 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

HiThere - 11 Dec 2005 05:33 GMT
> 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!   :-)


Greg Maxey - 11 Dec 2005 05:38 GMT
I have deleted the origin of this thread, but I am a charitable minded
person.  My PayPal address is gmaxey@mvps.org ;-)

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

>> ActiveDocument.Save
>> objPPT.ActivePresentation.Saved = True
[quoted text clipped - 11 lines]
> updates slides in Word docs...consider yourself silently thanked by
> her too!   :-)
HiThere - 11 Dec 2005 06:00 GMT
>I have deleted the origin of this thread, but I am a charitable minded
>person.  My PayPal address is gmaxey@mvps.org ;-)

What does that mean?  Helmut, the guy who provided the solution, won't see
my reply?
Greg Maxey - 11 Dec 2005 06:11 GMT
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
;-)

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

>> I have deleted the origin of this thread, but I am a charitable
>> minded person.  My PayPal address is gmaxey@mvps.org ;-)
>
> What does that mean?  Helmut, the guy who provided the solution,
> won't see my reply?
Helmut Weber - 11 Dec 2005 10:27 GMT
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! ;-)

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

HiThere - 11 Dec 2005 15:34 GMT
>>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...

    :-)
HiThere - 14 Dec 2005 18:24 GMT
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
Word Heretic - 20 Dec 2005 15:15 GMT
G'day "HiThere" <nospamplease@aol.com>,

<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:

>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!
[quoted text clipped - 88 lines]
>
>End Sub
Jonathan West - 21 Dec 2005 14:36 GMT
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

Signature

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

> G'day "HiThere" <nospamplease@aol.com>,
>
[quoted text clipped - 160 lines]
>>
>>End Sub
Word Heretic - 21 Dec 2005 23:27 GMT
G'day "Jonathan West" <jwest@mvps.org>,

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:

>Steve,
>
[quoted text clipped - 5 lines]
>Why variables should be declared properly
>http://www.word.mvps.org/FAQs/MacrosVBA/DeclareVariables.htm
Karl E. Peterson - 03 Jan 2006 23:52 GMT
You must've been battling trolls, for I can't even begin to imagine the
counter-argument that isn't more than sheer nonsense.
Signature

Working without a .NET?
http://classicvb.org/

> G'day "Jonathan West" <jwest@mvps.org>,
>
[quoted text clipped - 16 lines]
>> Why variables should be declared properly
>> http://www.word.mvps.org/FAQs/MacrosVBA/DeclareVariables.htm

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.