Convert VBA to AppleScript
Can anyone help me convert the VBA script to AppleScript? I've tried time and time again to use curl w/o any success. Any guidance would be appreciated.
Dim ldq As HTTPClass
Set ldq = New HTTPClass
'Set up the query fields for the POST form
ldq.Fields("ldapserverid") = "prod"
ldq.Fields("rootdn") = "ou=realWorker, o=company.com"
ldq.Fields("check") = "C"
ldq.Fields("someid") = ID
ldq.Fields("condition1") = "and"
ldq.Fields("condition2") = "and"
'Open a connection to the server
ldq.OpenHTTP ("search.company.com")
'Send the POST request
Debug.Print ldq.SendRequest("ldq/result.jsp", "POST")
test = ldq.SendRequest("ldq/result.jsp", "POST")
'Get the SOAP envelope
soap = ldq.SendRequest("ldq/viewSOAP.jsp", "GET")
'Clean up
Set ldq = Nothing
Hi
Theirs a pretty in depth tutorial over at MACTECH, which I think will aid your in your code transition
Moving from Microsoft Office VBA to AppleScript:
MacTech's Guide to Making the Transition
http://www.mactech.com/vba-transition-guide/index.html
Budgie
Message was edited by: Budgie
Their is also the possibility you could use the "do Visual Basic" command, not to sure about thta though
Similar Messages
-
Before I changed to Mac, I ran this User Defined Function in Excel;
Function Taxdue08(Salary)
If Salary > 180000 Then
Taxdue08 = (58000 + (Salary - 180000) * 0.45) + (Salary * 0.015)
Else
If Salary > 80000 Then
Taxdue08 = (18000 + (Salary - 80000) * 0.4) + (Salary * 0.015)
Else
If Salary > 34000 Then
Taxdue08 = (4200 + (Salary - 34000) * 0.3) + (Salary * 0.015)
Else
Taxdue08 = ((Salary - 6000) * 0.15) + (Salary * 0.015)
End If
End If
End If
End Function
So when i clicked a cell and executed the function it would ask me for an amount (so i would click the cell containing the amount) and then it would display the answer... But now I'm using a mac and Excel 2008 so I'm told I have to use Applescript.. So I tried to convert the code to Applescript as follows:
on Taxdue08(Salary)
if Salary is greater than 180000 then
set Salary to ((58000 + (Salary - 180000) * 0.45) + (Salary * 0.015))
else if Salary is greater than 80000 then
set Salary to ((18000 + (Salary - 80000) * 0.4) + (Salary * 0.015))
else if Salary is greater than 34000 then
set Salary to ((4200 + (Salary - 34000) * 0.3) + (Salary * 0.015))
Else
set Salary to (((Salary - 6000) * 0.15) + (Salary * 0.015))
end if
end Taxdue08
but, not surprisingly I guess, nothing happens when I run the script in Excel 2008... Can anyone help me out here?
Cheers
RayThanks Pierre... As you can tell, I'm a real noobie... I guess what I don't understand is how to actually make it do something... In Windows Excel I would execute the user defined function in a cell and it would ask me for an amount, then I would click on a cell that had an amount in it and the function would use that amount to do the math and display the result in the cell where i executed the function...
But with the applescript, if i click on a cell and then run the script, nothing happens... There must be some code I'm missing which asks for input from the user and then uses that input for the equation, in this case it would replace the variable 'Salary', then, following your code, the appropriate calculated result would be placed in the variable theTaxDue, which would then be displayed in the cell... Any ideas on what the missing code might be?
Cheers,and I appreciate your help...
Ray -
Converting Simple Indesign AppleScript to Javascript
Hi,
I have been using as imple Indesign AppleScript but need to convert it to javascript and have no prior experience. I've been reading the Adobe pdf about scripting and it is great as it shows the differences between the 3 (as, js, vb) but I'm still having trouble figuring out how this would conver. Would anyone be able to show me the converted result?
AppleScript:
tell application "Adobe InDesign CS5.5"
tell every document
set visible of layer "Interactive - Web" to true
set visible of layer "Interactive - Print" to false
end tell
end tell
Javascript:
var myDocuments = app.documents.everyItem(); // something like this?
It hides/shows the visibility of 2 specific layers for all opened documents. I pretty much need to hide/show 2 specific layers ina book and this should/can accomplish that.
Thanks for any help!This should work:
var documentsArray = app.documents.everyItem().getElements();
for (var i = 0; i < documentsArray.length; i++) {
var document = documentsArray[i];
var layers = document.layers;
layers.itemByName("Interactive - Web").visible = true;
layers.itemByName("Interactive - Print").visible = false;
Also, it might be possible to do this without using "getElements" which "resolves the object specifier", eliminating the need for the "for" loop. Something like this:
app.documents.everyItem().layers.itemByName("Interactive - Web").visible = true;
app.documents.everyItem().layers.itemByName("Interactive - Print").visible = false; -
Converting old Quark applescript to InDesign - problems
Hello
I'm converting an old Quark applescript to InDesign CS3 finally. I'm having a problem with placing, scaling and adjusting images.
Here's how it works ... a user fills out a Microsoft Word form, which a designer unlocks and pastes into the layout, and then runs the script. The image frames are all labeled, and that's how I'd like to call them.
Here's a snippet of the Quark portion that I'm having a problem with ...
set Todayicon to item (offset from list Dayicons of Todayval) of DayIconEPS
set Todayiconpath to (OPIpath and Todayicon as string)
set Todayicon to item 1 of Todayiconpath
set scale of Todayicon to {"65","65"}
set offset of Todayicon to {"-1p2","0p5"}
And here's what I'm thinking I need to do in InDesign CS3 ...
set Todayicon to item (offset from list Dayicons of Todayval) of DayIconEPS
set Todayiconpath to (OPIpath and Todayicon as string)
set Todayicon to item 1 of Todayiconpath
set TodayiconTransformationMatrix to make transformation matrix with properties {horizontal scale factor:0.65, vertical scale factor:0.65, geometric bounds:[-14,-5]
transform Todayicon in inner coordinates with matrix TodayiconTransformationMatrix
Unfortunately, the script errors out when it tries to make the transformation matrix, even though I'm following the examples in the Working with Tranformations in Applescript pdf.
Any ideas? I guess I can put dummy images in the layout and call a "Place" to override the dummy images, which should keep the scale, but it doesn't help me when I need to offset the images sometimes.Philip Regan wrote: "The new scripting model with all of its touted advantaged is really poorly executed."
While I didn't design the scripting model for transformations, and disagree with some of the decisions made in the design, I understand that InDesign's transformations architecture had to be rewritten for CS3. There were too many cases in CS2 where objects could not be returned to their original coordinates after transformation. The scripting implementation pretty much had to go along with the change in the underlying architecture.
If you'd rather things work the way they worked in CS2, why not use the set of transform "wrappers" that I wrote and included in the transform tutorial? With those functions, you don't really need to worry about the new model.
Thanks,
Ole -
Convert to Profile (Applescript)
Hi All,
I'm looking for an applescript command to perform "Convert to Profile" on my current document in Photoshop CS3. I've seen a Javascript solution in this Forum, but nothing for applescript. Any help would be appreciated.
I would also love to know how to set PS preferences so that all new docs created in a given image mode use a pre-set profile.
Thanks,
JamieJamie, you can set Photoshop's colour settings by name string before opening/creating your files. You can decide how to treat profiles there. This should give you some help.
tell application "Adobe Photoshop CS2"
-- Record current settings
set User_CS to color settings
-- Apply your settings
set color settings to "Marks Test"
end tell
tell application "Adobe Photoshop CS2"
activate
tell document 1
-- Apply a colour profile
if color profile name ≠ "Europe ISO Coated FOGRA27" then
set color profile name to "Europe ISO Coated FOGRA27"
end if
-- Convert to colour profile
if color profile name ≠ "U.S. Sheetfed Coated v2" then
convert to profile "U.S. Sheetfed Coated v2" intent absolute colorimetric with dithering without blackpoint compensation
end if
end tell
end tell
tell application "Adobe Photoshop CS2"
-- Put back settings
set color settings to User_CS
end tell -
Convert Javascript to Applescript
Hi,
I need to convert javascript to Apple script. Please help!!!
try {
app.activeDocument.layers.getByName( '.ARD' ).remove(); } catch (e) {};
MOhantell application "Adobe Illustrator"
tell the current document
try
delete (the first layer whose name is ".ARD")
end try
end tell
end tell
It's always a help if you state the language choice in the question…
Edit… a change of string filter
tell a
tell application "Adobe Illustrator"
tell the current document
try
delete (the first layer whose name ends with ".ARD")
end try
end tell
end tell -
How to convert tokens to different tokens in applescript?:P
hey guys,
I am sorry for the vague question but i really need to explain what i mean.
I have this pdf file, of which i want to copy the text from to word, however it has many tokens such as the sigma and the square root sign that cant be converted to word or pages. What i am thinking of doing is copy the text and then convert it in applescript so "square root sign" becomes "square" in letters and the greek letter mu becomes just "M"
-- incomplete Script on
set question to display dialog "which text to convert?" default answer "something"
set all to text returned of question
-- script off
and then i change the odd tokens in all to tokens word understand.
I understand that this might not even be possible in applescript, but if it is possible in any way or you have any suggestion than i would love to hear them please.
I just want the odd tokens to adapt to conventional ones.
Thank you so much in advancehey guys,
I am sorry for the vague question but i really need to explain what i mean.
I have this pdf file, of which i want to copy the text from to word, however it has many tokens such as the sigma and the square root sign that cant be converted to word or pages. What i am thinking of doing is copy the text and then convert it in applescript so "square root sign" becomes "square" in letters and the greek letter mu becomes just "M"
-- incomplete Script on
set question to display dialog "which text to convert?" default answer "something"
set all to text returned of question
-- script off
and then i change the odd tokens in all to tokens word understand.
I understand that this might not even be possible in applescript, but if it is possible in any way or you have any suggestion than i would love to hear them please.
I just want the odd tokens to adapt to conventional ones.
Thank you so much in advance -
Converting simple AppleScript to JavaScript
Hello to all,
I need to convert a simple AppleScript to JavaScript, but as I don't know one bit about JavaScript, is there anyone willing to help me out ?
Here is the AppleScript:
tell application "Adobe Photoshop CS5"
activate
set display dialogs to never
set thisdoc to current document
tell thisdoc
resize image resolution 300 resample method none
end tell
end tell
Very simple script to resize some low-res pictures without touching final resolution.
Thanks !This will change the resolution only..
app.displayDialogs = DialogModes.NO;
activeDocument.resizeImage(undefined, undefined, 300, ResampleMethod.NONE); -
How do I create a multiple find and replace for Excel in AppleScript?
I have a large dataset in Excel that I have to do a multiple find/replace in (changing USPS state abbreviations to their full names). In searching the Microsoft boards--I was directed to use Applescript, and even the documented help with Excel was recommeding this. Unfortunately, there wasn't much help potinting me in the specific direction I needed. Any ideas on how I should write this script?
Thanks!I'm confused as to why Applescript (or any script would be helpful).
You'd have to type the abbreviation and the full name into the script, the same as just using Find and Replace All. You wouldn't gain anything by using a script. Is there more to this task than you've let on?
MacTech has an article on converting from VBA to Applescript, but I'm not sure if it would have any ideas on your specific problem: http://www.mactech.com/vba-transition-guide/index-toc.html -
How do I convert VBA script so it does the same thing on a Mac as it does in Microsoft Office?
We have a Word file that references an Excel spreadsheet, and uses some clever coding (done by someone else, I assume it's clever but it may not be) to make the document more interactive.
How can I do this please?Hi Basilisk,
quoted from here http://en.wikipedia.org/wiki/VisualBasic_forApplications :
"Support for VBA in the Mac OS X version of Microsoft Office was dropped with the release of Microsoft Office 2008 for Mac. The official reason given was that VBA relied heavily on machine code written for the PowerPC architecture, and that rewriting this code for dual PowerPC/Intel architectures would have added another 2 years to the development of the suite. However, the office suite can to an extent be automated using AppleScript. In a press statement released on May 13, 2008, Microsoft's Macintosh Business Unit (Mac BU) announced that VBA will be returning in the next version of Office for Mac. Microsoft has also clearly stated that they have no plans to remove VBA from the Windows version of Office."
Regards
Stefan -
Applescript: How to start an application with parameters
AppleScripters,
I am sorry if I have posted this in the inappropriate forum, I saw none with a specific regard to AppleScript.
Let us presume that we have a regular shell script which when initiated from the Terminal has code such as what follows hereupon:
/Applications/SeaMonkey.app/Contents/MacOS/seamonkey -editor /Users/joebuffoon/myhomepage.htm
In order to convert this to AppleScript I was told to use:
activate application "Seamonkey"
This works, but seems not to support the ability to either provision the "-editor" argument (such argument would impel Seamonkey to start in "composer mode"), nor does it seem to provision the allowance of supplying a file to open in "composer mode" as the aforementioned command line in my shell script would.
Can I ask if anyone has any idea how I can do this in AppleScript?
I am also interested to find a good book on Apple Scripting (preferably one available in PDF format as well, if possible).
Thanks in advance,
StuartI saw none with a specific regard to AppleScript
http://discussions.apple.com/forum.jspa?forumID=724 -
[b]Tutorial:[/b] Simplify Developing OLE Automation Code Using VBA
INTRODUCTION
Automating Office applications from Oracle Forms can be a tedious, frustrating, and time-consuming process. Because the OLE2 and CLIENT_OLE2 built-ins do not validate the automation commands that they relay, code that compiles without errors often dies at runtime with a not-so-helpful error code. This tutorial will demonstrate how to simplify the development of automation code using a tool that ships with all Microsoft Office editions -- the Visual Basic for Applications (VBA) IDE.
The VBA IDE, a core Office component, is a full-fledged development environment featuring code completion, basic syntax highlighting, context-driven help and a runtime debugger. Its Object Browser provides a convenient means of browsing the Word object model, as well as searching by keyword.
For those who may not interested in following this tutorial in detail, I would like to stress the usefulness of the Object Browser as a tool for inspecting the functions supported by OLE server applications and, perhaps more importantly, valid values for function arguments. Whether/not anyone buys the assertion that starting with VBA prototypes is far more productive than pounding out OLE2 code from the very start, they will find the Object Browser invaluable as a reference -- I rely on it exclusively for this sort of documentation.
A BRIEF INTRODUCTION TO THE VBA IDE & THE OBJECT BROWSER UTILITY
Try this:
1. Open Word
2. Launch the VBA IDE by pressing <Alt><F11>
3. Open the Object Browser by pressing <F2>
The Object Browser allows you to visually navigate Word's class hierarchy. Its user interface is a bit crowded, so controls are unlabeled. Hovering the mouse cursor above a control will display a tooltip explaining that control's purpose. The browser's scope can be narrowed by using the Project/Library combo. Typing a keyword or substring in the Search Text combo and clicking on the Search button will cause all classes/members whose name contains the specified search text to be listed in the Search Results pane. Selecting an item from this list will update the two panes below it, showing the selected class, and its members. Beneath the Classes and Members panes is an untitled pane, gray in color, which displays details for the selected class/member, including hyperlinks to relevant information such as arguments, their types and allowable values. If Visual Basic Help is installed, pressing <F1> will display help on a selected class/member. (This feature can be installed from your Office install CD, if necessary.)
NOTE: While it is possible to cut-and-paste the code examples that follow, I highly recommend that they be typed in by hand. Doing so will provide a better understanding of how the IDE's code completion behaves. Use code completion most efficiently by not using the mouse or <Enter> key when selecting from completion lists. Instead, just type enough letters to select the desired list element, then continue along as if you had typed the entire element, typing the next operator in your statement. It really is slick!
HELLO WORLD - VBA-STYLE
1. Open Word
2. Launch the VBA IDE by pressing <Alt><F11>
3. Select Module from the Insert menu.
4. In the blank area that appears, enter the following code:
Public Sub HelloWorld()
Documents.Add
Selection.TypeText ("Hello, world!")
End Sub5. Press <F5> to run the code.
If you switch back to Word by pressing <Alt><F11>, there should appear a newly-created document containing the text Hello, world!.
A MORE AMBITIOUS EXAMPLE
In this example, we will launch Word, type some text, and alter its formatting. For the purposes of this tutorial, consider it the process we wish to automate from within Forms.
1. If Word is running, close it.
2. Open any Office application except Word, such as Excel, Outlook or PowerPoint
3. Launch the VBA IDE by pressing <Alt><F11>.
4. Select References from the Tools menu -- a dialog should pop up.
5. From within this dialog, locate and select Microsoft Word <version> Object Library, then click OK.
6. Select Module from the Insert menu.
7. In the blank area that appears, enter the following code:
Public Sub LaunchWord()
Dim app As Word.Application
Set app = CreateObject("Word.Application")
app.Visible = True '!!! IMPORTANT !!!
app.Documents.Add
With app.Selection
.TypeText "This is paragraph 1."
.TypeParagraph
.TypeText "This is paragraph 2."
.TypeParagraph
.TypeText "This is paragraph 3."
End With
With ActiveDocument
.Paragraphs(1).Range.Words(3).Bold = True
.Paragraphs(2).Range.Words(3).Italic = True
.Paragraphs(3).Range.Words(3).Underline = True
End With
End Sub8. Press <F5> to run the code.
A new Word session should have been launched. Switch to it, to view the results of our handiwork!
TAILORING VBA CODE INTENDED FOR OLE2 CONVERSION
Now, things get a bit uglier. The code listed above gives a good idea of how concise VBA code can be, but With blocks and chained object references do not translate readily into OLE2 code. Here's the same process, rewritten in a more OLE2-friendly style. Note the numerous intermediate object references that have been declared.
Public Sub LaunchWord()
Dim app As Word.Application
Dim doc As Word.Document
Dim docs As Word.Documents
Dim pars As Word.Paragraphs
Dim par As Word.Paragraph
Dim wrds As Word.Words
Dim sel As Word.Selection
Dim rng As Word.Range
Set app = CreateObject("Word.Application")
app.Visible = True '!!! IMPORTANT !!!
Set doc = app.Documents.Add
Set sel = app.Selection
sel.TypeText "This is paragraph 1."
sel.TypeParagraph
sel.TypeText "This is paragraph 2."
sel.TypeParagraph
sel.TypeText "This is paragraph 3."
Set pars = doc.Paragraphs
'select third word of first paragraph and make it bold
Set par = pars.Item(1)
Set rng = par.Range
Set wrds = rng.Words
Set rng = wrds.Item(3)
rng.Bold = True
'select third word of second paragraph and italicize it
Set par = pars.Item(2)
Set rng = par.Range
Set wrds = rng.Words
Set rng = wrds.Item(3)
rng.Italic = True
'select third word of second paragraph and underline it
Set par = pars.Item(3)
Set rng = par.Range
Set wrds = rng.Words
Set rng = wrds.Item(3)
rng.Underline = True
End Sub
TRANSFORMATION: CONVERTING VBA CODE INTO PL/SQL
Here is the PL/SQL counterpart to our previous VBA routine. Compare printouts of the two and note their similarities. Notice the need for argument lists -- this causes the code to fluff up quite a bit, and really interferes with readability.
PROCEDURE LAUNCH_WORD IS
v_app OLE2.OBJ_TYPE; -- Application
v_doc OLE2.OBJ_TYPE; -- Document
v_docs OLE2.OBJ_TYPE; -- Documents collection
v_pars OLE2.OBJ_TYPE; -- Paragraphs collection
v_par OLE2.OBJ_TYPE; -- Paragraph
v_wrds OLE2.OBJ_TYPE; -- Words collection
v_sel OLE2.OBJ_TYPE; -- Selection
v_rng OLE2.OBJ_TYPE; -- Range
v_args OLE2.LIST_TYPE; -- OLE2 argument list
BEGIN
/* launch Word and MAKE IT VISIBLE!!! */
v_app := OLE2.CREATE_OBJ('Word.Application');
OLE2.SET_PROPERTY(v_app, 'Visible', TRUE);
/* initialize key object references */
v_docs := OLE2.GET_OBJ_PROPERTY(v_app, 'Documents');
v_doc := OLE2.INVOKE_OBJ(v_docs, 'Add');
v_sel := OLE2.GET_OBJ_PROPERTY(v_app, 'Selection');
/* type first paragraph */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 'This is paragraph 1.');
OLE2.INVOKE(v_sel, 'TypeText', v_args);
OLE2.DESTROY_ARGLIST(v_args);
OLE2.INVOKE(v_sel, 'TypeParagraph');
/* type second paragraph */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 'This is paragraph 2.');
OLE2.INVOKE(v_sel, 'TypeText', v_args);
OLE2.DESTROY_ARGLIST(v_args);
OLE2.INVOKE(v_sel, 'TypeParagraph');
/* type third paragraph */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 'This is paragraph 3.');
OLE2.INVOKE(v_sel, 'TypeText', v_args);
OLE2.DESTROY_ARGLIST(v_args);
/* set reference to Paragraphs collection */
v_pars := OLE2.GET_OBJ_PROPERTY(v_doc, 'Paragraphs');
/* select third word of first paragraph and make it bold */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 1);
v_par := OLE2.INVOKE_OBJ(v_pars, 'Item', v_args);
OLE2.DESTROY_ARGLIST(v_args);
v_rng := OLE2.GET_OBJ_PROPERTY(v_par, 'Range');
v_wrds := OLE2.GET_OBJ_PROPERTY(v_rng, 'Words');
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 3);
v_rng := OLE2.INVOKE_OBJ(v_wrds, 'Item', v_args);
OLE2.SET_PROPERTY(v_rng, 'Bold', TRUE);
/* select third word of second paragraph and italicize it */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 2);
v_par := OLE2.INVOKE_OBJ(v_pars, 'Item', v_args);
OLE2.DESTROY_ARGLIST(v_args);
v_rng := OLE2.GET_OBJ_PROPERTY(v_par, 'Range');
v_wrds := OLE2.GET_OBJ_PROPERTY(v_rng, 'Words');
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 3);
v_rng := OLE2.INVOKE_OBJ(v_wrds, 'Item', v_args);
OLE2.SET_PROPERTY(v_rng, 'Italic', TRUE);
/* select third word of second paragraph and underline it */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 3);
v_par := OLE2.INVOKE_OBJ(v_pars, 'Item', v_args);
OLE2.DESTROY_ARGLIST(v_args);
v_rng := OLE2.GET_OBJ_PROPERTY(v_par, 'Range');
v_wrds := OLE2.GET_OBJ_PROPERTY(v_rng, 'Words');
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 3);
v_rng := OLE2.INVOKE_OBJ(v_wrds, 'Item', v_args);
OLE2.SET_PROPERTY(v_rng, 'Underline', TRUE);
END;
REFACTORING FOR REUSABILITY AND READABILITY
While the previous procedure runs without errors, it suffers from poor readability which, in turn, makes it difficult to maintain. Here, we address those issues by moving repetetive low-level operations into separate procedures.
PROCEDURE LAUNCH_WORD IS
v_app OLE2.OBJ_TYPE; -- Application
v_doc OLE2.OBJ_TYPE; -- Document
v_docs OLE2.OBJ_TYPE; -- Documents collection
v_sel OLE2.OBJ_TYPE; -- Selection
v_args OLE2.LIST_TYPE; -- OLE2 argument list
BEGIN
/* launch Word and MAKE IT VISIBLE!!! */
v_app := OLE2.CREATE_OBJ('Word.Application');
OLE2.SET_PROPERTY(v_app, 'Visible', TRUE);
/* create a new Word document */
v_docs := OLE2.GET_OBJ_PROPERTY(v_app, 'Documents');
v_doc := OLE2.INVOKE_OBJ(v_docs, 'Add');
v_sel := OLE2.GET_OBJ_PROPERTY(v_app, 'Selection');
/* add a few paragraphs */
PRINT_PARAGRAPH(v_sel, 'This is paragraph 1.');
PRINT_PARAGRAPH(v_sel, 'This is paragraph 2.');
PRINT_PARAGRAPH(v_sel, 'This is paragraph 3.');
/* apply formatting */
APPLY_FORMATTING(v_doc, 1, 3, 'Bold', TRUE);
APPLY_FORMATTING(v_doc, 2, 3, 'Italic', TRUE);
APPLY_FORMATTING(v_doc, 3, 3, 'Underline', TRUE);
END;
PROCEDURE APPLY_FORMATTING(
v_doc OLE2.OBJ_TYPE,
v_paragraph_num NUMBER,
v_word_num NUMBER,
v_attribute VARCHAR2,
v_value BOOLEAN) IS
v_pars OLE2.OBJ_TYPE; -- Paragraphs collection
v_par OLE2.OBJ_TYPE; -- Paragraph
v_wrds OLE2.OBJ_TYPE; -- Words collection
v_rng OLE2.OBJ_TYPE; -- Range
v_args OLE2.LIST_TYPE; -- OLE2 argument list
BEGIN
/* set reference to Paragraphs collection */
v_pars := OLE2.GET_OBJ_PROPERTY(v_doc, 'Paragraphs');
/* get specified paragraph */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, v_paragraph_num);
v_par := OLE2.INVOKE_OBJ(v_pars, 'Item', v_args);
OLE2.DESTROY_ARGLIST(v_args);
/* get words for specified paragraph */
v_rng := OLE2.GET_OBJ_PROPERTY(v_par, 'Range');
v_wrds := OLE2.GET_OBJ_PROPERTY(v_rng, 'Words');
/* apply formatting to word found at specified index */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, v_word_num);
v_rng := OLE2.INVOKE_OBJ(v_wrds, 'Item', v_args);
OLE2.SET_PROPERTY(v_rng, v_attribute, v_value);
END;
PROCEDURE PRINT_PARAGRAPH(v_sel OLE2.OBJ_TYPE, v_text VARCHAR2) IS
v_args OLE2.LIST_TYPE;
BEGIN
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, v_text);
OLE2.INVOKE(v_sel, 'TypeText', v_args);
OLE2.DESTROY_ARGLIST(v_args);
OLE2.INVOKE(v_sel, 'TypeParagraph');
END;
CONCLUSION
It is my hope that this tutorial, despite it's introductory nature, has demonstrated the value of the VBA IDE, the ease with which automation processes can be prototyped using VBA, the noticeable similarity between VBA automation routines and their Forms PL/SQL counterparts, and the advantages of testing automation processes within the VBA IDE. Please feel free to follow up with any specific questions or concerns you may have.
Thanks,
Eric Adamson
Lansing, Michigan
FINAL NOTE: These examples use the OLE2 built-in, and will operate correctly when called from forms running in the Form Builder OC4J. Deploying them to an Oracle Application Server will launch Word on the server itself (if available), which is usually not the developer's intent! Automating Word client-side via web forms requires adding WebUtil support. Adapting the code for WebUtil is trivial -- just replace all instances of OLE2 with CLIENT_OLE2. Adapting forms for WebUtil and configuring OLE support into your Oracle Application Server, however, are beyond the scope of this tutorial.
REVISION HISTORY
This promises to be something of a 'living document'. I've snuck changes through without comment in the past, but in the future, I'll try to document significant changes here.
2006-08-21
* Prefaced boring subject line with text: 'Tutorial:' to clarify purpose
* Added emphasis on value of Object Browser as a referenceThanks James, for your kind words. I do hope this information will help folks out. I honestly believe that tinkering around in the VBA IDE will prove highly gratifying for automation developers. It can be assured that learning to make Word jump through hoops is much more straight-forward in this environment. I'm not one for mottos, but if I were pressed for a cheesy motto, I would say: First, make it work. Then, make it work in Oracle!
Once the idea has sunk in, that Visual Basic routines for automating Word are exact analogs to their OLE2 counterparts, we can remove keywords like Oracle and PL/SQL from our Google searches on Word automation which, at least in this context, are the proverbial kiss of death. Suddenly we find ourselves liberated by the possibility of steal-, ahem... borrowing ideas from the Visual Basic* community!
As for links, my link of choice is invariably http://groups.google.com -- if you don't already use it at least ten times a day, you must try it. This is the venerable USENET archive, including the holdings of now-extinct DejaNews. Another possible site of interest is http://word.mvps.org/FAQs/MacrosVBA, which may serve as a good starting point for those who wish to learn how to do fancy tricks with Word using VBA.
If these links don't prove immediately helpful, please feel free to give specifics on the sort of operations you are interested in automating, and I'll see if I can post an example that addresses it.
Regards,
Eric Adamson
Lansing, Michigan
PS: I do hope, as people read my posts, with every other acronym being VBA, that they are not mistakenly hearing a call to learn Visual Basic. I say this, not because I believe learning VB would be a Bad Thing, but because I assume that few of us feel we have the time to learn a new programming language. Despite having come to the Oracle camp already knowing VB/VBA, and having acquired a fair bit of experience with automating Office applications as an Access developer, I remain confident that what I am suggesting people attempt does not rise to the level of learning a language. What I am suggesting is that they learn enough of the language to get by.
*VB vs. VBA
Just a quick word on this, as readers may wonder why I seem to use these terms interchangeably. Visual Basic (VB) can refer to either a development platform or a programming language. Visual Basic for Applications (VBA) is a language -- more precisely, it is a subset of the Visual Basic language. One purchases VB, usually quite intentionally. VBA is included with Microsoft Office, as is VBA's development environment, the VBA IDE. The key distinction between VB and VBA is that VBA cannot be used to create self-contained executables. Rather, VBA relies on VBA-enabled applications, such as Microsoft Office applications, to serve as a container for VBA code, and to provide a runtime environment for that code. For the purposes of discussing OLE Automation, VB and VBA are quite interchangeable. -
please help
I have sql work in access but in sql server I get error
TRANSFORM First(Eval1to4.answer) AS FirstOfanswer SELECT Eval1to4.evalOid, Membershiptypemap.mappedvalue as membership, First(Eval1to4.answer) AS [Total Of answer] FROM (Members RIGHT JOIN (Eval1to4 LEFT JOIN Orders ON Eval1to4.evalOid = Orders.oid)
ON Members.CID = Orders.cid) LEFT JOIN MembershipTypeMap ON (Members.MembershipStatus = MembershipTypeMap.membershipstatus) AND (Members.Membership = MembershipTypeMap.membershiptype) WHERE Orders.program = 20501225 AND Eval1to4.evalProgID=20501225 GROUP BY
Eval1to4.evalOid, Membershiptypemap.mappedvalue PIVOT Eval1to4.questionID
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'Eval1to4'.
please helpHow can we help you reading the article ?!?
Please clarify what do need more help. Did you read the article Uri suggested ?
This might help you in general:
>> 'First' is not SQL Server function. The FIRST() function returns the first value of the selected column. In SQL Server you use "top 1" with "order by" hint.
>> In each virtual table like "select from (<this is virtual table>)" you need to write a name. For example "select from (<this is virtual table>) as T"
>> After this, you should read the article and understand the pivot format in SQL Server.
Please read this article! Converting from MS Access [VBA] to SQL Server [T-SQL]
http://social.technet.microsoft.com/wiki/contents/articles/22731.convert-vba-code-to-transact-sql.aspx
I hope this is useful :-)
[Personal Site] [Blog] [Facebook] -
Since I have been posting to these forms, I have been annoyed by the conversions that are done to my posts. A word surrounded by asterisks gets bolded. When I decide to make a link to a post, I can never remember the exact format. When I posted AppleScript code, I found that it is squish to the left. The AppleScript I have posted here gets around these problems.
usage: What you need to do is copy the text that you wish to post to the clipboard then run this AppleScript then paste the text into your post.
Robert
This AppleScript program is designed to convert HTML links to forum posts, to convert special characters to their HTML symbols, and to preserve formatting.
1) When the clipboard contains a link to a forum reply page.
The AppleScript forums designers specify a roundabout way for you to reference a particular web post. Here is that way:
a) Find the particular post you wish to reference.
b) Click on the reply icon.
c) Copy the Web address to the clipboard .
d) Run this AppleScript to convert the Web address.
e) Paste the converted Web address into your post.
For example, this AppleScript will convert this Web address:
http://discussions.apple.com/post!reply.jspa?messageID=9003196
into this Web address:
http://discussions.apple.com/message.jspa?messageID=9003196#9003196
2) Assume that the clipboard contains text to convert.
Many of the special characters are used to indicate formatting in the forums.
See "Other formating tags are available as shown below" in
http://discussions.apple.com/help.jspa
This AppleScript will converted to HTML these special symbols in order to preserve the original characters. Also, this AppleScript preserves indentation used in programs or Terminal output.
a) Copy the text to the clipboard .
b) Run this AppleScript to convert the text
c) Paste the converted text into your post.
For example, the asterisks will be preserved:
mac $ ls *oup*
Youpi Key Editor.plist Youpi Key.app alias
For example, the indentation will be preserved:
on adding folder items to this_folder after receiving dropped_items
repeat with dropped_item_ref in dropped_items
display dialog "dropped files is " & dropped_item_ref
end repeat
end adding folder items to
Author: rccharles
-- Write a message into the event log.
log " --- Starting on " & ((current date) as string) & " --- "
set theClip to the clipboard
if characters 1 thru 33 of theClip as string = "http://discussions.apple.com/post" then
http://discussions.apple.com/post!reply.jspa?messageID=9003196
http://discussions.apple.com/message.jspa?messageID=9003196#9003196
set theClip to alterString(theClip, "post!reply", "message")
set {frontPart, postNumber} to textToList(theClip, "=")
set theClip to theClip & "#" & postNumber
else
-- must be the first change so as not to cause problems.
-- and there must not be any HTML numbers on the clipboard.
set theClip to alterString(theClip, "#", "#")
set theClip to alterString(theClip, "&", "&amp;")
set theClip to alterString(theClip, " ", "&nbsp;")
set theClip to alterString(theClip, " ", " ") -- contains two spaces
set theClip to alterString(theClip, "!", "!")
set theClip to alterString(theClip, "[", "[")
set theClip to alterString(theClip, "]", "]")
set theClip to alterString(theClip, "<", "<")
set theClip to alterString(theClip, "*", "*")
set theClip to alterString(theClip, "+", "+")
set theClip to alterString(theClip, "_", "_")
set theClip to alterString(theClip, "--", "--")
set theClip to alterString(theClip, tab, " ")
set theClip to "<tt>" & theClip & "</tt>"
end if
set the clipboard to theClip
on alterString(thisText, delim, replacement)
set resultList to {}
set {tid, my text item delimiters} to {my text item delimiters, delim}
try
set resultList to every text item of thisText
set text item delimiters to replacement
set resultString to resultList as string
set my text item delimiters to tid
on error
set my text item delimiters to tid
end try
return resultString
end alterString
-- textToList was found here:
-- http://macscripter.net/viewtopic.php?id=15423
on textToList(thisText, delim)
set resultList to {}
set {tid, my text item delimiters} to {my text item delimiters, delim}
try
set resultList to every text item of thisText
set my text item delimiters to tid
on error
set my text item delimiters to tid
end try
return resultList
end textToListThe first thing that you need to do is to make the text into an AppleScript program.
start the AppleScript Editor
/Applications/AppleScript/Script Editor.app
copy the text to the Applescript editor.
save the text to a file as an application and do not check any of the boxes below.
!http://farm4.static.flickr.com/3544/3390737677_645a847e28.jpg?v=0!
now, let's build a link to a post.
get the link to a reply.
Goto this Webpage:
http://discussions.apple.com/post!reply.jspa?messageID=9003196
Copy the Web page address from the top of your Web browser page. This is the standard highlight the address then do a command+c
Now you should run my AppleScript program by going back to the Script Editor. Optional, click the words *event log* to see the debug information. Click on the run icon.
!http://farm4.static.flickr.com/3423/3391549168_9ce8b6fcd9.jpg?v=0!
The link has been modified. Paste the link onto your Web page. This is the standard command+v.
For a more typical usage, placed the program on the dock or make an alias on the desktop.
Robert
Name: alter-clipboard
Input: Clipboard
Output: Clipboard
This AppleScript program is designed to convert a forum-reply web address to a link to a forum post, to convert special characters to their HTML symbols, and to convert programming language code to a form that does not get mangled.
1) When you wish to reference another Apple discussion forum post, I found the process convoluted. The Apple form software does not provide for the display of a form post link. Instead, you must construct the link from a reply post. This AppleScript simplifies the process.
When the clipboard contains a link to a forum reply page, do the conversion.
Here is that way:
a) Find the particular post you wish to reference.
b) Click on the reply icon.
c) Copy the Web address to the clipboard (command+c).
d) Run this AppleScript to convert the Web address.
e) Paste (command+v) the converted Web address into your post.
For example, you:
• Want to reference a post on how to improve the performance of Tiger. You find a post by Texas Mac Man with a list of possibilities.
• Click on the Reply option and highlight the Web address because you know the address contains a reference to this post.
• Type command+c to copy the address to the clipboard. The clipboard now contains:
http://discussions.apple.com/post!reply.jspa?messageID=9124252
• Run this AppleScript to convert the Web address. The clipboard now contains:
http://discussions.apple.com/message.jspa?messageID=9124252#9124252
• Type command+v to paste the address into your new post.
2) Assume that the clipboard contains special symbols or formated programming language code to convert.
This AppleScript will converted special symbols used in these forums to a form not used by the forum software in order to preserve the original characters.
For the symbols, see:
See "Other formating tags are available as shown below" in
http://discussions.apple.com/help.jspa#format
An alternative to using these symbols is document in this post:
http://discussions.apple.com/thread.jspa?messageID=607563
Also, this AppleScript preserves indentation used in programs or Terminal output.
a) Copy the text to the clipboard .
b) Run this AppleScript to convert the text
c) Paste the converted text into your post.
For example, the asterisks will be preserved:
mac $ ls *oup*
Youpi Key Editor.plist Youpi Key.app alias
For example, the indentation will be preserved:
on adding folder items to this_folder after receiving dropped_items
repeat with dropped_item_ref in dropped_items
display dialog "dropped files is " & dropped_item_ref
end repeat
end adding folder items to
Author: rccharles
Copyright 2009 rccharles
GNU General Public License
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
For a copy of the GNU General Public License see <http://www.gnu.org/licenses/>.
-- Write a message into the event log.
log " --- Starting on " & ((current date) as string) & " --- "
set theClip to the clipboard
if characters 1 thru 33 of theClip as string = "http://discussions.apple.com/post" then
http://discussions.apple.com/post!reply.jspa?messageID=9003196
convert to:
http://discussions.apple.com/message.jspa?messageID=9003196#9003196
set theClip to alterString(theClip, "post!reply", "message")
set {frontPart, postNumber} to textToList(theClip, "=")
set theClip to theClip & "#" & postNumber
else
-- must be the first change so as not to cause problems.
-- and there must not be any HTML numbers on the clipboard.
set theClip to alterString(theClip, "#", "#")
-- You need to use either the numeric form of the HTML symbol or to
-- do the translation has seen below.
set theClip to alterString(theClip, "&", "&amp;")
set theClip to alterString(theClip, " ", "&nbsp;")
set theClip to alterString(theClip, " ", " ") -- contains two spaces
set theClip to alterString(theClip, "!", "!")
set theClip to alterString(theClip, "[", "[")
set theClip to alterString(theClip, "]", "]")
set theClip to alterString(theClip, "<", "<")
set theClip to alterString(theClip, "*", "*")
set theClip to alterString(theClip, "+", "+")
set theClip to alterString(theClip, "_", "_")
set theClip to alterString(theClip, "--", "--")
set theClip to alterString(theClip, tab, " ")
set theClip to "<tt>" & theClip & "</tt>"
end if
set the clipboard to theClip
on alterString(thisText, delim, replacement)
set resultList to {}
set {tid, my text item delimiters} to {my text item delimiters, delim}
try
set resultList to every text item of thisText
set text item delimiters to replacement
set resultString to resultList as string
set my text item delimiters to tid
on error
set my text item delimiters to tid
end try
return resultString
end alterString
-- textToList was found here:
-- http://macscripter.net/viewtopic.php?id=15423
on textToList(thisText, delim)
set resultList to {}
set {tid, my text item delimiters} to {my text item delimiters, delim}
try
set resultList to every text item of thisText
set my text item delimiters to tid
on error
set my text item delimiters to tid
end try
return resultList
end textToList -
Help with Applescript to find cell
I'm attempting to convert some Excel Applescripts over to Numbers and can't find a method to "find".
In Excel for example, I have:
set foundCell to (find keyColumn what searchSymbol look at whole look in values search order by rows after (get last cell of keyColumn) search direction search previous without match case)
The applescript dictionary seems feature rich but no find? Unimaginable, so there must be something I'm over-thinking.I'm guessing you're looking for something like this...
Working with a table something like this:
Symbol
ABC
DEF
JKL
DEF
XYZ
Then a script like this should do what you what you want:
property keyColumn : "A"
property searchSymbol : "DEF"
property targSht : "Sheet 1"
property targTbl : "Table 1"
tell application "Numbers"
set foundCell to my findLastVal(targSht, targTbl, keyColumn, searchSymbol)'s properties
--in line above, depending on what you want, substitute name, row, etc for properties
end tell
to findLastVal(tSht, tTbl, kCol, sVal)
tell application "Numbers" to tell front document's sheet tSht's table tTbl
repeat with i from row count to 1 by -1
tell column kCol's cell i
if its value is sVal then return it
end tell
end repeat
end tell
end findLastVal
To find the first match in a column you would simply remove the negative decrement, something like this:
repeat with i from 1 to row count
If you're working with very long columns it can be more efficient to first read the values into an AppleScript list and look for a match in the list rather than asking Numbers to read a cell and look for a match on each iteration. But the above approach should work well with moderately sized data sets.
SG
Maybe you are looking for
-
How to restore OS from time machine to a non-booting Mac HD
My Mac HD has been playing up for some time and today it finally decided to not work at all. This was after I had installed 10.7.3 yesterday. I booted from my OS Leopard CD and installed it on my second HD which is usually used for data storage. I d
-
Select Query Results to a .csv file????
Hello All, I have a question in Oracle, if anyone knows how to do this. Please help me. How can I get the results of select query in Oracle loaded into a Excel file (.csv) file. Thanks in Advance, Sarada.
-
Can terms be excluded from add-on searches?
I want to search for a Google add-on that has nothing to do with image or translate. When I type those terms as -image and -translate, I still get results for those terms. Is there a way to narrow a search down by excluding terms? Thanks in advance.
-
Hi, i am having a issue with pivot table's property startColumn. Below is the issue. i have two pivot tables switcher facet - 1 pivot table - 1(lets say pv1) , command button (lets say c1) facet - 2 pivot table - 2(l
-
Hi All: I have an issue wherein the user ran ACH transaction in FLB1 for the date 4/11/2008. But the system pulled in the cash from a previous date 02/08/2008 and displayed as not processed. However, that transaction of the date 02/08/2008 was proces