Copy link to clipboard
Copied
I am saving a txt file and I want it to open (execute) in excel after the script creates it.
I probably can't do it in JS and need to do a little doScript in VB and AS
Can anyone show me how to do this.
Something like
function openWith (myFile, myProgram)
{
if ($.os.match(/Mac/i)) app.doScript ("appleOpenWith (" + myFile + ", " + myProgram + ")", ScriptLanguage.APPLESCRIPT_LANGUAGE);
else app.doScript ("windowsOpenWith (" + myFile + ", " + myProgram + ")", ScriptLanguage.VISUALBASIC);
}
function appleOpenWith (myFile, myProgram)
{
\\ SOME APPLE SCRIPT HERE. WHAT????
}
function windowsOpenWith(myFile, myProgram)
{
\\ SOME VB HERE. WHAT????
}
Thanks
Trevor
here's a sample of how to create an excel file using jsx/vbs
...// creates and runs a vbs file that creates an excel file
// carlos canto
// http://forums.adobe.com/message/5615242?tstart=0#5615242
var vbscript = [
'Err.Clear',
'On Error Resume Next \r',
'set app = GetObject(,"Excel.Application") \r',
'If (Err.number <> 0) Then',
' Set app = CreateObject("Excel.Application")',
'End If \r',
'app.visible = true',
'set newDoc = app.Workbooks.Add',
'app.Range("A1:C1") = Array("1", "2", 3)',
'app.Dialogs(5).Show \r
Copy link to clipboard
Copied
Hi Trevor, thanks, I think vbscript does not support initializing multidimensional arrays, they must be explicitly populated...I think
this script opens a text file
// creates and runs a vbs file that opens a TAB delimited TXT file
// carlos canto
// http://forums.adobe.com/message/5615242?tstart=0#5615242
var vbscript = [
'Err.Clear',
'On Error Resume Next \r',
'set app = GetObject(,"Excel.Application") \r',
'If (Err.number <> 0) Then',
' Set app = CreateObject("Excel.Application")',
'End If \r',
'app.visible = true',
'app.Workbooks.OpenText ("C:\\Users\\carlos\\Desktop\\dataTabDelimited.txt")\r',
'set app = nothing'
];
var vbfile = File(Folder.desktop +"/textFileOpenWithExcel.vbs");
vbfile.open('w');
vbfile.write(vbscript.join('\r'));
vbfile.close();
vbfile.execute();
Copy link to clipboard
Copied
Hi Carlos,
Thanks again that finshes of the answers up the original question.
One last (I HOPE) question.
What would I change in this line
'app.Workbooks.OpenText ("C:\\Users\\carlos\\Desktop\\dataTabDelimited.txt")\r',
to get excel to open an html file?
The same question over to Hans in applescript
What would I change in this line
+ 'open text file filename (POSIX file "' + macFileName + '" as text) data type delimited tab true\r'
to get excel to open an html file?
I would guess it would be
+ 'open HTML file filename (POSIX file "' + macFileName + '" as HTML)\r'
Is that correct?
Last night I put together a script (for illustrator) that exports info about embed links to an excel sheet using the apple and VB scripts from here, seems to work well.
I can't publish it here (copyright) but I shall send in a couple of hours the 5 of you private mails with a link to the script for you to use if it is of any use for you.
Thanks again
Trevor
Copy link to clipboard
Copied
Good morning,
as you can read (;-)) in the AS-Excel-Reference you've posted (4th post) there's no open command for html-files.
Commands offered: open; open FileMaker file; open links; open text file; open workbook || (excel 2004)
So I guess a html-file has to be parsed to a delimited text file first ...
Hans
Copy link to clipboard
Copied
Hi Hans and Carlos
I see that using Carlos's script in 25 above works for html files as well
One just needs to change the file suffix from .txt to.html and get rid of the as text... and excel opens the html file without problem.
'app.Workbooks.OpenText ("C:\\Users\\Trevor\\Desktop\\myHTML.html")\r',
So I guess in apple script one this should work
+ 'open text file filename (POSIX file "' + macFileName + '")\r'
Parsing to text delimited is not an option because in this case I loose the images stored in the indesign table which is exported as an html file.
I see I wont be able to send the link to the script I made until Sunday.
Have a good weekend
Trevor