Microsoft Shell Controls & Automations leaves WORD open

happyjoyhappyjoy 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? :?


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

Comments

  • happyjoyhappyjoy Member Posts: 10
    ...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:18
  • ravnenravnen Member Posts: 12
    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é Ravn
  • happyjoyhappyjoy Member Posts: 10
    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:18
  • LouisLouis Member Posts: 78
    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 ?

    L
Sign In or Register to comment.