Re: Alternatives to Word (was: Re: Script problems with BBEd
Re: Alternatives to Word (was: Re: Script problems with BBEd
- Subject: Re: Alternatives to Word (was: Re: Script problems with BBEd
- From: billp <email@hidden>
- Date: Tue, 11 Dec 2001 20:13:40 -0600
Scott,
Thanks for taking a stab. I could not get it to work. The best
it does is go to the Execution Error that "Microsoft Word got
an error. AppleEvent timed out."
I inserted another "end tell" after the Word section, as
the script would not compile without it. But it would not make
the script work anyway. Nor if it was placed after the Excel
portion.
Word had ample memory (36mb), so that should not have been a
problem. I also made sure that "Disk:Table" was changed so that
the "Disk" portion of the path was an actual volume available on
my desktop. Maybe this would be better if directed to the Temporary
Items folder?
I also tried to maximize each open window, but I'm doubtful I placed
the command to do so in the right place:
tell application "Microsoft Excel"
repeat until number of documents is 0
-> set WindowState of ActiveWindow to xlMaximized
Save document 1 In "CD_Burn:Table" & (number of documents) As xlText
Close document 1
end repeat
end tell
You can see my disk name inserted ("CD_Burn").
Anyway, if someone else has an idea how to convert the EMF objects
in Word, one-by-one, to proper Tables, using pure VBA commands, I'd
love for you to jump in!
Thanks,
Bill Planey
>
-- AppleScript here, but with Visual Basic embedded. Safety Goggles
>
required.
>
>
tell application "Microsoft Word"
>
do Visual Basic "For Each OLEobject in ActiveDocument.Shapes
>
If OLEobject.Creator = 1297307460 then
>
OLEobject.Activate
>
End If
>
Next "
>
>
-- Now, all the Excel objects are open as worksheets inside the Excel
>
application.
>
>
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
>
So, the script above will find all the Excel objects in the Word document and
>
activate them all. Then it will save each one and close it in Excel. Each
>
table will be saved as tab-separated text, on the disk "Disk" with names
>
"Table1", "Table2", etc.
>
>
What happens if the embedded Excel spreadsheet has more data than is
>
displayed,
>
or has more than one worksheet pages, will influence what the "Save as
>
xlText"
>
produces and may produce some dialogs.
>
>
If a company sends you a Word file that has an embedded spreadsheet, you
>
may be
>
getting way more information than you expected (and way more than they
>
thought
>
they were sending you.)
I have placed the remainder of your original reply down here for those
interested in reading it (actually all this text preceded the above
lines):
>
On Thu, 6 Dec 2001 19:16:05 -0600, billp <email@hidden> asked,
>
>
> And while on the subject of Word and problems with it...
>
>
>
> What really screws me up is when a client sends over a Word file
>
> wherein the tables have somehow been created in and linked to Excel;
>
> you cannot, for example, select any text in the table within Word.
>
> When you click somewhere on the table, handles appear (as on any graphic)
>
> at the corners and in-between. Double-clicking takes you into Excel
>
> where, finally, you can access the data at the character level.
>
>
This is an embedded file, using Microsoft's Object Linking and Embedding
>
"technology." The object consists of a graphic that provides the
>
apperence of
>
the object, and the actual spreadsheet file itself, so you can open it by
>
double-clicking it.
>
>
So I'd suggest you could get the embedded file to open in Excel, and then
>
save
>
it as tab-delimited text from there, rather than turning it into a Word
>
table as
>
an intermediary.
>
>
[...]
>
> What I cannot figure out how to do is to have AppleScript perceive
>
> these things as the kinds of objects they are and to have them
>
> automatically converted to the Word Table format. Has anyone out there
>
dealt
>
with
>
> this?
>
>
The AppleScript dictionary of Word doesn't expose this sort of object.
>
You can
>
use Visual Basic to access these things, and use AppleScript to run a
>
piece of
>
Visual Basic code to get what you want. Here are the fundamentals you may be
>
able to use to build a solution from:
>
>
An OLE object in a document is part of the document's "Shapes" collection.
>
You
>
can specifically identify Excel objects by their "Creator" property. Excel
>
objects have 1297307460 as their creator. (That odd number is the integer
>
representation of the four-byte 'XCEL' signature for Excel.) So, you can
>
iterate through document's Shapes collection and get all the Excel objects:
>
>
' Warning: Visual Basic code follows. Viewer discretion is advised.
>
For Each OLEobject in ActiveDocument.Shapes
>
If OLEobject.Creator = 1297307460 then
>
' Do your processing of it here
>
End If
>
Next
>
>
Now, just what is the processing to do? Probably the best thing to do
>
would be
>
to tell the object to activate, and then address further AppleScript
>
commands to
>
Microsoft Excel.