Cannot open a new Microsoft Word document in Objective-C - objective-c

I have a task to open Microsoft Word and create a new document in Objective C.
If I am running an Apple Script below in the Script Editor, it works fine and a new Microsoft Word document gets created:
tell application "Microsoft Word" to make new document
BUT, if I am trying to call the same script from Objective-C code (see it below), it only opens the Microsoft Word application, but does not create a new document :
NSDictionary* errorDict;
NSAppleScript * appleScript = [[NSAppleScript alloc] initWithSource:
#"tell application \"Microsoft Word\" to make new document"];
[appleScript executeAndReturnError:&errorDict];
I guess there is something to do with the permissions.
Any ideas are very welcome!

Related

Lotus Notes VBA make MS Word visible

All,
I am trying to use MS Word to print the current web page.
I have a print button that call an agent and run on the server.
The problem is that it make MS Word visible on the server console and not on the user machine.
If I run my agent locally, it will make MS Word visible on the user (or my machine).
I know this is all working like it should but I am wondering if there is a way to make MS Word visible when called from a button on the web calling an agent.
this is some of the code I am talking about:
Dim objWord As Variant
Dim docWord As Variant
Set objWord = CreateObject("Word.Application")
objWord.Visible = true
Dim object As NotesEmbeddedObject
Dim rtitem As Variant
Set docWord = objWord.Documents.Open("L:\Lotus\Domino\data\domino\html\Attachments\cal\templates\gage-grid111.docx")
Basically no. All LotusScript on the web runs on the Domino server and can't do anything with client software, and there's nothing you can do about that as far as I know.
Some alternatives might be possible depending on the requirements of your application.
Firstly, does the thing you're printing have to be a Word document? If the same content can be generated with HTML and CSS, then you could open that as a normal web page and print it using client-side javascript.
If it really must be a Word document, then one of the following options might suit you:
Store the Word document in a Notes document accessible to the web user, or in some other server-side location accessible by a URL, then show the web user a link to the Word document so they can download and print it; or...
I've never tried this, but it might be possible to control Word on the client machine using ActiveXObject in javascript, or there may be some other Windows-only javascript feature to do this. If this is possible, browser support is likely to be limited, and subject to security restrictions.
What exactly do you mean by "use Word to print the current page"? If it's the exact contents of the screen, why use Word when a browser can print the page? How is your web page created, using a Notes form or XPages?
Probably the best you can do is use CSS directives for when the document is printed. Either make a 2nd form that displays the data exactly as you want them printed, or put a hidden div in the same form (e.g. at the bottom) that contains the info to be printed. Use CSS in such a way that the original info isn't printed, only the normally hidden div.
You could print to a PDF file, I don't know if/how printing to Word works.

Why does the Document_Open Macro not run in Word when opening the document from Delphi using Office Automation

I am trying to use Office Automation in Delphi Tokyo to open a Word document (using Word 2016). The document has a Document_Open macro that prompts the user to optionally run another macro.
When I run the following code:-
Doc := IDispatch(WordApp.Documents.Open([*filename*])) as _Document;
the document opens, but the Document_Open macro does not run. Also, if I try to run the second (main) macro manually, I get an error saying "The macros in this project are disabled ..."
However, if I open the same document from the Word file menu, the macros run as expected, so they are clearly not disabled.
The VBA project is digitally signed and Word is set to "Disable all macros except digitally signed macros".
How do I get my macros to run when opening the document from within Delphi?
BrakNicku led me to the answer.
I have found that unless you set WordApp.AutomationSecurity to msoAutomationSecurityByUI, macros are disabled irrespective of the settings in Word.
So the answer to my question is:-
WordApp := GetActiveOleObject('Word.Application');
//store AutomationSecurity setting
LogonAutomationSecurity := WordApp.AutomationSecurity;
try
//set AutomationSecurity
WordApp.AutomationSecurity := msoAutomationSecurityByUI;
Doc := IDispatch(WordApp.Documents.Open([*filename*])) as _Document;
...
finally
WordApp.AutomationSecurity := LogonAutomationSecurity;
end;
Then, provided the user's Trust Settings allow the macro to run, it will!
I hope this helps someone.

how to open the vba form in external application like notepad and notead++

I want to know how to read the ms access form (vba form) via external application
like (notepad,notepad++).
In vb6 application can be able to read the [control name],[code] in the external application (notepad,notepad++).
but, there is no option for to do the same operation in the ms access forms.
when i open the form in the database i can ,but not in the notepad and notepad++.
It is possible or not (or) is there any other way to do this action.
You can only access the form code that is shown in the VBA editor. In VB and C# you can view the code that actually creates the control objects and initialises them (I think it is this that you are referring to). You can't see this code in Access / VBA.
If you want to edit the code in Notepad++ simply copy and paste it from the VBA code editor (which is shown when you press ALT+F11).
PS. I use a access addin called OASIS-SVN that can export all object definitions as text files, I probably does it as described here
If you want to edit VBA projects files outside from VBE, you first need to Export them (using Right-click->Export a file) and save them somewhere.
Then you'll be able to open them with notepad(++).
Don't forget to Import them back into your VBA Project after editing.

"Close" Button of programmatically created Excel doesn't kill the process Excel.exe

Good day everyone, I've got a rough question for you.
I've programatically created an excel document using Interop.Excel and when I close it programmatically process EXCEL.EXE has been killed. BUT, when I close the document by clicking "Close" button the process is being alive. Does anyone know what should I release in my code to make my application works correctly? And, btw, why does it might happen?
You have to close the Application using interop while coding:
For example:
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Document doc = app.Documents.Open("C:\\DocWord.docx");
doc.Activate();
//Do some stuff
//Close document
doc.Close();
//Close application!
app.Quit();
Closing the final document in Excel does not close Excel. You can verify this yourself by opening Excel in the normal way and File -> Close. This is by design and standard for any application following the Multiple Document Interface (MDI) model.
To exit the process, use Application.Quit where Application is an instance of the Excel application object.

Open a SaveFileDialog using the Microsoft Project application

I'm working on a VBA macro which generates an Excel report out of a Microsoft Project planning.
In order to save the report, I have to open a Save File Dialog by calling
GetSaveAsFilename("name", , , "Title"), but I don't want to use the Excel.Application for this because I'm supposed to activate it first which doesn't make sense.
How should I call GetSaveAsFilename through the Microsoft Project application?
MS Project uses FileSaveAs instead of GetSaveAsFilename, which has several arguments. If you leave them blank you will just get the SaveAs dialog box.