Re: How to convert tables inserted as pictures back to text?

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: John McGhie [MVP - Word] (john_at_mcghie.name)
Date: 03/31/04


Date: Wed, 31 Mar 2004 22:39:49 +1000

Hi Bill:

That's *MY* damn soap-box, you interloper... gerrroff!!

I knew I was going to regret getting involved in this thread.

This responds to microsoft.public.mac.office.word on Mon, 29 Mar 2004
18:20:12 -0600, BillP <n3wsr3ad3r_@_sbcglobal.net>:

> I did receive the following suggestion for the VBA phrasing from one Helen
> Feddema, who is a VB expert in New York, after I posed the question to her:
>
> >Bill,
>
> >There are several ways you could get at these objects. To select one, a
> >line like the following will do:
> >
> > Selection.GoTo What:=wdGoToGraphic, Which:=wdGoToFirst, Count:=5,
> >Name:=""
> >
> >(this selects the fifth image in a Word document).

Try this (all as ONE line)...

Selection.GoTo What:=wdGoToGraphic, Which:=wdGoToAbsolute, Count:=5

They are functionally equivalent, but using the second statement enables you
to increment the Count parameter to step through the graphics in the
document.

> >If you want to cycle through all of the images, since there is no
> >Graphics or Images collection in Word (though there is a Tables
> >collection), you could set up an incrementing lngCount variable and
> >access each image in turn, or try the wdGoToNext named constant as with
> >tables.

She's made a mistake: there *is* a collection, but it's called "Shapes" not
graphics or images. Note: I haven't checked this on the Mac, I wonder if
she knows something I don't: maybe the Shapes collection does not exist on
the Mac: that's unlikely I think. Anyway... this is what she means:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 1/30/2004 by John McGhie
'

For i = 1 To ActiveDocument.Shapes.Count

   Selection.GoTo What:=wdGoToGraphic, Which:=wdGoToAbsolute, Count:=i

   MsgBox "Number " & Str(i)

Next i

End Sub

> ...but unfortunately, I could not make it work. Syntax error or compile
> error.

Yeah. Although this VBA looks simple, we're actually getting into the more
arcane parts of VBA where you can expect some fireworks getting it to go on
the Mac. I have not tested any of these examples on the Mac (sorry: I
haven't time to re-install Office X tonight) but it may well be that they
won't compile and/or run.

The implementation of VBA in Mac Word 2001/X is intentionally very limited
to keep the price of Office down :-) Regrettably, the fix would be a huge
and massively expensive undertaking, and there are many places they could
spend their money that I think Mac users would appreciate more. Couple that
with the fact that VBA is a dead technology anyway, and you can see that
when it comes to a choice of where they are going to spend development
funds, I think we can safely assume it won't be VBA... VBA is being
replaced simply because it was designed to be small and efficient and easy
to use in happier times when a small number of computers networked together
were all operated by friends who could be trusted. By design, VBA cannot be
made sufficiently secure for today's Internet firestorm, so they are
replacing it on the PC too, with VB dot Net. Dot Net is not only much
faster, more flexible, and more powerful, but -- by design -- it doesn't
trust *anybody* :-) It's designed to remain secure in a
massively-distributed application where the entire world is networked
together.

> I made sure that the document I tried it on had more than five of
> such objects before trying it... Also, I am quite lost reading her last
> paragraph. I am not that good with VBA; my best bits of code have come from
> Word's AS recordability, and the incredible kindness of strangers on message
> boards like this one.

Yeah. There's a reason I told you I wouldn't attempt this in Mac Word :-)

Quite frankly, unless you are very good at VBA, I would not be walking in
this valley of death. It's just too hard, wrestling with a language that is
incomplete on the Mac, a development environment that is incomplete on the
Mac, and trying to learn VBA at the same time. Find yourself a copy of Word
2003 on a PC and write your macro there: you will save literally weeks of
your time.

I would not have chosen the GoTo command to do this with (although, it does
save you having to work out what is a picture and what is not).

The following code will loop through all of the Shapes in the document, and
for each one that is a Drawing Canvas, copy it.

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 1/30/2004 by John McGhie
'

Dim aPic As Shape

For Each aPic In ActiveDocument.Shapes

MsgBox aPic.Type

    If aPic.Type = msoCanvas Then
        aPic.Select
        Selection.Copy
    End If

 ' Put the rest of your code here
 
Next aPic

End Sub

' MsoShapeType can be one of these MsoShapeType constants.

' msoAutoShape
' msoCanvas
' msoComment
' msoFormControl
' msoCallout
' msoChart
' msoEmbeddedOLEObject
' msoFreeform
' msoGroup
' msoLine
' msoLinkedOLEObject
' msoLinkedPicture
' msoMedia
' msoOLEControlObject
' msoPicture
' msoPlaceholder
' msoScriptAnchor
' msoShapeTypeMixed
' msoTable
' msoTextBox
' msoTextEffect

Again: notice that those are all prefixed "mso"? That means they are part
of Microsoft Office, but not necessarily available in Word, particularly on
the Mac. So if you get problems, that could be a reason.

> I fully expect Microsoft to not only disappoint

Hey, that's my line! Seriously: If you think Microsoft is bad, try some of
the others :-)

> I find it icky in the extreme that I have to deal with MS Word at all; only
> the reality of the marketplace (i.e., that 99% of this type of document is
> prepared in Word) keeps me having to create kludgy solutions.

Again: Try the others :-) Word in my experience is the best there is, by
quite a long way :-) If you really enjoy tilting at windmills, try doing
this in FrameMaker :-)

Hope this helps

--
Please post all comments to the newsgroup to maintain the thread.
John McGhie, Consultant Technical Writer
McGhie Information Engineering Pty Ltd
Sydney, Australia.  GMT + 10 Hrs
+61 4 1209 1410, mailto:john@mcghie.name


Relevant Pages

  • Re: automatic save
    ... The Help in Word 2004 VBA talks about it, ... feature (PC or Mac) since...... ... McGhie Information Engineering Pty Ltdhttp://jgmcghie.fastmail.com.au/ ... The macro listed at Graham Mayor's ...
    (microsoft.public.mac.office.word)
  • Re: Word 2004 VBA -> Applescript
    ... I have the actual article in from of me its in the Mailed version of the Oct Mac Addict Magazine that comes with the CD. ... I don't no whether it means That VBA will be totally unusable in Mac Version from now on. ... You can write very serious applications in VB.NET (or any other .NET ... language you prefer, including COBOL...). ...
    (microsoft.public.mac.office.word)
  • Re: How to convert tables inserted as pictures back to text?
    ... the Mac: that's unlikely I think. ... ' Macro recorded 1/30/2004 by John McGhie ... Although this VBA looks simple, we're actually getting into the more ... By design, VBA cannot be ...
    (microsoft.public.word.vba.general)
  • Re: How to convert tables inserted as pictures back to text?
    ... the Mac: that's unlikely I think. ... ' Macro recorded 1/30/2004 by John McGhie ... Although this VBA looks simple, we're actually getting into the more ... By design, VBA cannot be ...
    (microsoft.public.word.tables)
  • Re: How to convert tables inserted as pictures back to text?
    ... the Mac: that's unlikely I think. ... ' Macro recorded 1/30/2004 by John McGhie ... Although this VBA looks simple, we're actually getting into the more ... By design, VBA cannot be ...
    (microsoft.public.word.vba.beginners)