Microsoft Shell Controls & Automations leaves WORD open

happyjoy
Member Posts: 10
Hello Friends! 
I've written a function in a codeunit based on code found here in another post that will print any file type from within Navision. It uses the "Microsoft Shell Controls and Automation" automation set. I'm using it to print multiple documents through seperate calls to the codeunit, passing a new filepath each time.
It works fine...except it doesn't close the WORD application when done (all documents are *.doc type). :oops:
I don't want to go with another method (i.e. Word Automation) because I want to keep the flexibility of printing multiple file types.
DOES ANY ONE KNOW HOW TO CLOSE THE APPLICATION THAT THE SHELL COMMANDS OPEN? :?

I've written a function in a codeunit based on code found here in another post that will print any file type from within Navision. It uses the "Microsoft Shell Controls and Automation" automation set. I'm using it to print multiple documents through seperate calls to the codeunit, passing a new filepath each time.
It works fine...except it doesn't close the WORD application when done (all documents are *.doc type). :oops:
I don't want to go with another method (i.e. Word Automation) because I want to keep the flexibility of printing multiple file types.
DOES ANY ONE KNOW HOW TO CLOSE THE APPLICATION THAT THE SHELL COMMANDS OPEN? :?
OBJECT Codeunit 50002 Print Any File { OBJECT-PROPERTIES { Date=04/24/09; Time=[ 3:14:54 PM]; Modified=Yes; Version List=FJL; } PROPERTIES { OnRun=BEGIN END; } CODE { PROCEDURE PrintAnyFile@1000000000(VAR FilePath@1000000011 : Text[250];VAR DIR@1000000012 : Text[250];VAR FileName@1000000013 : Text[250]); VAR Ret@1000000009 : Integer; CommonDialogMgt@1000000008 : Codeunit 412; PrintThisFile@1000000007 : Text[250]; ObjShell@1000000004 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{13709620-C279-11CE-A49E-444553540000}:'Microsoft Shell Controls And Automation'.Shell"; objVerbs@1000000003 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{1F8352C0-50B0-11CF-960C-0080C7F4EE85}:'Microsoft Shell Controls And Automation'.FolderItemVerbs"; objFolder@1000000002 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{BBCBDE60-C3FF-11CE-8350-444553540000}:'Microsoft Shell Controls And Automation'.Folder"; objFolderItems@1000000001 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{744129E0-CBE5-11CE-8350-444553540000}:'Microsoft Shell Controls And Automation'.FolderItems"; objFolderItem@1000000000 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{FAC32C80-CBE4-11CE-8350-444553540000}:'Microsoft Shell Controls And Automation'.FolderItem"; Text000L@1000000010 : TextConst 'ENU=Couldn''''t find the file %1.\Please check that the path and filename is correct.'; BEGIN // FILEPATH = WHOLE FILE PATH (C:/DRIVE/FOLDERS/SUBFOLDERS/EXAMPLE.DOC) // DIR = DIRECTORY LIST OF FILE PATH ONLY (C:/DRIVE/FOLDERS/SUBFOLDERS/ ) // FILENAME = FILE NAME ONLY (EXAMPLE.DOC) IF ISCLEAR(ObjShell) THEN CREATE(ObjShell); IF NOT EXISTS(FilePath) THEN ERROR(Text000L,FilePath); objFolder := ObjShell.NameSpace(DIR); objFolderItems := objFolder.Items; objFolderItem := objFolderItems.Item(FileName); objFolderItem.InvokeVerb('PRINT'); objVerbs := objFolderItem.Verbs; END; BEGIN END. } }
"For in much wisdom is much grief, and he who increases knowledge increases sorrow." - Eccl. 1:18
0
Comments
-
...ALSO....to make matters even more complicated....I now need to be able to set the printer and printer tray that these documents will print from. Does anyone know how to do that with the automation? Do I do this as a seperate function prior to calling my code?"For in much wisdom is much grief, and he who increases knowledge increases sorrow." - Eccl. 1:180
-
Hi,
In order to close word, you will have to create a automation to this.
The way you have done it, opens any document in the program which you chose for the type of documents.
You can see in codeunit, Attachment Managment i think, how to open word with a given file.
About the Printer and printer tray, i haven't seen any with such functionality. My best guess would be the word Automation.
Best Regards
René Ravn0 -
Thanks Ravnen. I'm trying to stay away form the WORD automation and allow this to work regardless of the application.
Somehow - when the code runs on the client's system - they don't experience this problem. SO...I guess word closing is a dead issue now.
However - I do still need to know if there's a slick way to set the printer for these documents that are printing from the MS Shell automation "print" verb.
Any ideas anyone???"For in much wisdom is much grief, and he who increases knowledge increases sorrow." - Eccl. 1:180 -
It"s a long time ago. Now, anyone a good tip ?
Did you found a solution to the printer selection within the MS Shell Automation ?
L0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions