macro for converting EMF tables in Word to normal cellular Tables 
Author Message
 macro for converting EMF tables in Word to normal cellular Tables

I do electronic publishing and have automated some of my workflow.  My
clients sometimes send Word files that have EMF (Excel MetaFile?) objects in
them, which render them for all intents and purposes graphics inside Word.
I need these to be converted to normal cellular rows and columns (Tables) so
that my script can work properly.

If I do this manually, I have to double-click each EMF object, and, after
Excel has been activated, select the corresponding rows and columns of cells
in Excel, copy the selection, close the worksheet, switch back to Word,
delete the (previously selected) object, and issue a paste command, which
places the cells selected in Excel where the EMF object used to be (but in
cellular format).

BTW, this is AppleScript, I am working on a Mac.  That should not be a
problem - as AppleScript can send VBA commands to Word and Excel, using the
"do Visual Basic" command. The Sub/End Sub lines are the only things that
are removed.

I want to build a decision tree in my script which, if EMF objects are
found, will convert them to proper Tables and then move on to other

The key is to avoid trying to use the AppleScript dictionaries of Word and
Excel, because their AppleScript implementation is buggy (at least that's
true of Word - I have less experience with Excel).  However, issuing a VB
command from AppleScript works just fine.  (I have been recently educated on
this point by Paul Berkowitz and other posters on this and other MS-related
newsgroup boards.)

Since most of you are no doubt working on the Windows side of things, I just
want to show you how a piece of VB code looks in its native and AppleScript
contexts.  The following (functional) code detects and activates each EMF
table.  Here is the pure VBA version:

    Sub test()
      For Each OLEobject In ActiveDocument.Shapes
          If OLEobject.Creator = 1297307460 Then
          End If
    End Sub

...and now the AppleScript version:

tell application "Microsoft Word"
    do Visual Basic "For Each OLEobject in ActiveDocument.Shapes
        If OLEobject.Creator = 1297307460 then
        End If
        Next "
end tell

Now, the hard part is to where Excel needs to be called to select the cells
that are linked with the object, copy, go back to Word, delete the selected
object, and paste the copied selection from Excel in its old place.  This is
where I need help.

I was given the following (as well as the preceding) code by another poster,
and, in the context of AppleScript, this is how Excel was called:

tell application "Microsoft Excel"
    repeat until number of documents is 0
    save document 1 in "Disk:Table" & (number of documents) as xlText
    close document 1
    end repeat
end tell

It looks like it's trying to write some kind of temporary files; anyway, the
script does not work.  Can anyone suggest a pure VBA approach?  I'll worry
about adding the AppleScript command framework.

Many thanks,

Bill Planey

Mon, 31 May 2004 06:56:43 GMT  
 [ 1 post ] 

 Relevant Pages 

1. SQL Tables and Normal Tables Together?

2. Converting MDB tables to SQLserver tables

3. Macro for Word Table of Contents

4. Macro Help recq for table conversion in Word

5. Word 2000 Tables/macro enquiry

6. Getting Table Number of Word Table

7. Import/Export to WORD XP Table to/from SQL Table

8. Macro to convert currency to words - Word 2000

9. Normalizing non-normal tables already containing data;OR changing columns into rows

10. Word Spreadsheet Functionality in Word Table

11. Converting word basic macros

12. Converting Outlook VBScript to VBA as Word Macro


Powered by phpBB® Forum Software