Good evening all...

I've been trying to set the Windows default file path and the default windows printer for an automated Word application via OLE.

I've been successful with the rest of the application, but for whatever reason, I've not been able to set these too parameters...it seems that I either receive a: Can't modify non-lvalue subroutine call at .... or something nothing happens at all.

All of the searching online seem to use the traditional syntax within perl, vb, etc, but alas, I've not had any luck. One article said that \s had to be at the end, but by default, there are not present. Another article said that an Add had to be one prior, but that hasn't helped, either.

Portions were adapted from another node 495229, Activestate VB code, MSDN, and numerous articles online, but none referring to this l-value problem...even when using the same syntax...

What am I missing?

Thanks in advance for any help...!

$word = CreateObject Win32::OLE 'Word.Application' or die $!; $word->{DisplayAlerts} = 0; if (${$env_ref}{DEBUG_AUDIT_REPORT_VISIBLE}) { $word->{'Visible'} = 1; } $document = $word->Documents->Add; ## Change the default save location: ##$word->Options->DefaultFilePath(wdDocumentsPath); my ($path_current); my ($path_default) = '\\\\trhmc-fs04\\users04\\u02904'; my ($path_new) = 'C:\\Documents'; ## Outputs: Default save path: (\\trhmc-fs04\users04\u02904) print "Default save path: (". $word->Options->DefaultFilePath(wdDocume +ntsPath) . ")\n"; ## Outputs: Default save path: (\\trhmc-fs04\users04\u02904) $path_current = $word->Options->DefaultFilePath(wdDocumentsPath); print "Default save path: (". $path_default . ")\n"; ## Re-assign the default path: ## Outputs: Can't modify non-lvalue subroutine call at report_db_devel +opment.pl line 1983. #$word->Options->DefaultFilePath(wdDocumentsPath) = $path_new; #print "New save path: (". $word->Options->DefaultFilePath(wdDocuments +Path) . ")\n"; ## Re-assign the default path to the SAME thing ## Outputs: Can't modify non-lvalue subroutine call at report_db_devel +opment.pl line 1994. #$word->Options->DefaultFilePath(wdDocumentsPath) = $path_default; #print "New save path: (". $word->Options->DefaultFilePath(wdDocuments +Path) . ")\n"; ## Outputs: Default new path: (\\trhmc-fs04\users04\u02904) $word->Options->DefaultFilePath( { 'wdDocumentsPath' => $path_new, }); print "New save path: (". $word->Options->DefaultFilePath(wdDocumentsP +ath) . ")\n"; ## Outputs: Default new path: (\\trhmc-fs04\users04\u02904) $word->Options->DefaultFilePath( { 'Path' => $path_new, }); print "New save path: (". $word->Options->DefaultFilePath(wdDocumentsP +ath) . ")\n"; ## Outputs: Use of unitilized value in print at report_db_development. +pl line 2014. print $word->Options->DefaultFilePath; ## Outputs: Use of unitilized value in print at report_db_development. +pl line 2018. print $word->Options->{'DefaultFilePath'}; ## Outputs: Use of unitilized value in print at report_db_development. +pl line 2021. print $word->Options->DefaultFilePath(); ## Outputs: \\trhmc-fs04\users04\u02904 print $word->Options->DefaultFilePath(wdDocumentsPath); ## Outputs: Default save path: (\\trhmc-fs04\users04\u02904) $path_new = $word->Options->DefaultFilePath(wdDocumentsPath); print "Default save path: (". $word->Options->DefaultFilePath(wdDocume +ntsPath) . ")\n"; foreach $path_new ( 'C:\Documents', 'C:\\Documents', 'C:\Documents\\', 'C:\\Documents\\', "C:\\Documents", "C:\\Documents\\", ) { ## Cannot modify non-lvalue subroutine call at ... #$word->Options->DefaultFilePath(wdDocumentsPath) = $path_new; print "Default save path: (". $word->Options->DefaultFilePath(wdDo +cumentsPath) . ")\n"; $word->Options->DefaultFilePath( { 'Path' => $path_new, 'wdDocumentsPath' => $path_new, 'Path:=wdDocumentsPath' => $path_new, }); print "Default save path: (". $word->Options->DefaultFilePath(wdDo +cumentsPath) . ")\n"; } ## Outputs: \\TRHMC-IMGDIS1\ECRTJPLF on NE01: print $word->{ActivePrinter}; ## Outputs: \\TRHMC-IMGDIS1\ECRTJPLF on NE01: my ($default_printer) = $word->{ActivePrinter}; print $default_printer; ## Outputs: \\TRHMC-IMGDIS1\ECRTJPLF on NE01: $word->{ActivePrinter} = '\\trhmc-prt6\EDNLJP5L'; print "Default printer: $word->{ActivePrinter}\n";
Saved macro when recording within Word:
Options.DefaultFilePath(Path:=wdDocumentsPath) = _ "\\trhmc-fs04\users04\U02904\audit_basic\cgi-bin\" ActivePrinter = "PDFill PDF Writer" ActivePrinter = "\\TRHMC-IMGDIS1\ECRTJPLF" ActivePrinter = "\\trhmc-prt6\EDNLJP5L"
and the result of the Object Browser within VB:

Property DefaultFilePath(Path As WdDefaultFilePath) as String

Member of Word.Options Property ActivePrinter as String

Member of Word.Application

In reply to Word wdDocumentsPath and ActivePrinter by nevinl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.