0

We made the copy from one server to another (Apache), and the following instructions no longer work, we have tried various guides but they do not work

Error code: Fatal error: Uncaught exception 'com_exception' with message 'Source: Microsoft Word Description: This command is not available because no document is open

We Have

  • Microsoft Office 2007
  • Windows Server

The code:

    $word = new COM("Word.Application") or die("Unable to instantiate Word");

    $word->visible=1;

    $wordDocument=$word->Documents->Open($_SERVER['DOCUMENT_ROOT'].$PATH."/modelli_doc/ModificheCDC1.docx");


    $bookmarkname = "mese";

    $objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname);

The exception is the line with ActiveDocument Any solution?

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Vazel
  • 1
  • You assign the document you open to a variable `$wordDocument` - why don't you use it: `$objBookmark = $wordDocument->Bookmarks($bookmarkname);` ? Does that still give the same error? If you look at the Word application (you do make it visible?) is the document open? – Cindy Meister Nov 21 '18 at 09:36
  • $objBookmark = $wordDocument->Bookmarks($bookmarkname) Fatal error: Call to a member function Bookmarks() on a non-object. No is not open Thanks – Vazel Nov 21 '18 at 09:42
  • Then you need to trouble-shoot the file path being passed to the Open method. Is it valid? Are you able to open the document manually in Word from this location? Does the code have permissions to access this location (since you mention it's changed)? – Cindy Meister Nov 21 '18 at 09:53
  • Yes is valid, yes i can open document manually. "Does the code have permissions to access this location (since you mention it's changed)", how i can verify? – Vazel Nov 21 '18 at 09:54
  • I don't know how to verify (no experience with your programing environment). Something you might try is to record a macro when opening manually and compare the file path Word records with what you're using. Also try *running* the recorded macro and see if that's successful. – Cindy Meister Nov 21 '18 at 09:57
  • I use the method is writable, and is readable for file, and return true – Vazel Nov 21 '18 at 09:59
  • Looks like you're trying to automate an Office product from a server environment. Do not do this. Period. This is an unsupported scenario. The internet is full of people asking questions like this and full of answers telling people not to do this. Search for "excel server" or "word server" here on StackOverflow, and the answers are all the same. Here's one I recently responded to. https://stackoverflow.com/questions/53104024/exception-calling-excel-interop/53106945#53106945 – Michael Gunter Nov 21 '18 at 17:48
  • And here's the Microsoft statement on this. FWIW, I've been building Office automation solutions for 20 years. You're headed down a very bumpy dead-end road if you continue doing this the way you are doing it. https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office – Michael Gunter Nov 21 '18 at 17:49
  • what is the solution?I did not understand much what you want to say – Vazel Nov 21 '18 at 17:55

0 Answers0