Hot Topic (More than 10 Replies) Open MS Word with Sesame value? (Read 1640 times)
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Open MS Word with Sesame value?
Feb 3rd, 2006 at 1:11am
Print Post Print Post  

Hi -

It is certainly easy to have Sesame open MS Word (and, of course other applications) using @ASynchShell. 

I was wondering whether it is possible to pass a value from a layout element in Sesame - to the "new document" in MS Word?

In other words, I want to take text from one of the layout elements and automatically have it inserted into the Word Document.

Am I dreaming ..... or must I wait for version 2.0 ?   lol
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Open MS Word with Sesame value?
Reply #1 - Feb 3rd, 2006 at 2:03am
Print Post Print Post  
Try this untested approach........

Make the Word document a Merge document with a merge field for the single element.  Used TempFile.csv as the Data Source in the sample below.
Do a simple File Write, creating an import file with the variable.
----------------------------------------------------
Code
Select All
var vHandle as Int
var vOK as Int

vHandle = FileOpen("C:\Folder\TempFile.csv")
FileWrite(vHandle, variable )
FileClose(vHandle)
vOK = @AsynchShell("Mergeletter.doc") 


--------------------------------------------------
You may want to add other control code, for example to confirm the handle or the file path exists.....
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Open MS Word with Sesame value?
Reply #2 - Feb 3rd, 2006 at 3:37am
Print Post Print Post  
Bob -

I'm not sure that I understand what you are suggesting and am still hoping that something "simple" is available in Sesame.

In the event it is not, I am considering another alternative that "should be" simple.

I want to start word with a macro running.  So, far I am running into an MS Word problem.  I recorded and saved the macro and am trying to start it with a switch.  I even set macro security to "low" to be sure that there was no "interference" with it running.

It's supposed to be very simple:  winword.exe /mmacroname.  Unfortunately when I try to run it, I get a

"Runtime Error 91 - "Object Variable or With Block Variable not set" or some such "garbage." 

Grrrrrr!


  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Open MS Word with Sesame value?
Reply #3 - Feb 3rd, 2006 at 5:23am
Print Post Print Post  
The suggestion I provided was for you to pass some type of variable to an internal field.  If you want to pass a variable when starting, then you must start Word and pass the variable, vs. calling a Filename.doc.

vOK = @AsyncShell("C:\Program Files\Microsoft Office\Office\Winword.exe c:\Folder\DocumentName.doc /mMacroName")

---------------------------------------
You can embed the macro in the Word document so it will run automatically on loading without passing a macro name.  But that is for another forum.

------------------------------------------
I think that message you referred to is related to the Visual Basic code associated with your Word macro.  Can you show the declaration section of the macro code?
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Open MS Word with Sesame value?
Reply #4 - Feb 3rd, 2006 at 4:45pm
Print Post Print Post  
Bob -

With regard to my Word macro problem, the "second" angle I've been playing with is this.

I thought that I could copy text to the clipboard from within Sesame. Haven't even tried it because I'm assuming that between Sbasic and or Sesame's macro, this would not be a problem.

All I want to do in Word is start a NEW (blank) document which I am already doing. When word is started, I simply want it to paste the clipboard to the blank document.  Using the switch in the @ASynchshell command would enable all programming to be done in Sesame except for the very simple recording of a Word macro to perform the paste.  

When I select "run" the macro in Word it does just what I want.

When I use the switch word.exe /mmacroname, I get the debug stuff I described.  If I look at the macro itself, I see:

Sub MacroPaste()
'
' MacroPaste Macro
' Macro recorded 2/3/2006 by Spencer Wulwick
'
   Selection.PasteAndFormat (wdPasteDefault)
End Sub

I posted this here only because you asked.  For my purposes, however, I do not want to get involved in this type of code.

I've recorded macros in Word many times in the past (long past) and had no problem starting Word with a switch, so I am baffled as to why I am having this problem.

Thanks, much, for trying to help.
« Last Edit: Feb 5th, 2006 at 6:31am by SpencerWulwick »  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Open MS Word with Sesame value?
Reply #5 - Feb 4th, 2006 at 6:07pm
Print Post Print Post  
Hi -

I am taking yet another approach, and I am so close to what I want to do, I can almost taste it.

My new "track" takes me back to a specific Sesame only question, so perhaps I can get some help.

Is there any way to trigger programming based on exiting another program and being left back in Sesame?

In other words, I am in a layout element in my Sesame database.  

I click a command button that takes me (using @ASynchShell programming) to MS Word.  When I exit MS Word, I am now back in my Sesame database.  Is there any way that I can have programming automatically execute in Sesame?

So far I can click on my button to open MS Word but then when I exit word I have to click on the button again to resume my programming.  

Not a bad solution if I have to live with it but I would rather not if I can make it even "slicker."

Eagerly waiting to be  inundated with suggestions.  lol
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Open MS Word with Sesame value?
Reply #6 - Feb 4th, 2006 at 8:50pm
Print Post Print Post  
Hi again -

Is anyone there?  I feel like I am having a one-sided converstion.  lol

I am hoping that if I present some code, someone will come up with an "alternative" for me. The following code works BUT I have to wait too long for Word to close (and, probably NOT long enough if I take too much time in MS Word).

Code
Select All
var n as int

      Clear(Mark)

      If @isblank(Mark)
      {
      Mark = "DOIT"
      n = @AsynchShell("C:\Sesame\data\email.doc")
      }

      loiter(30000)

      if MARK = "DOIT"
      {
      LastEMail = @insert("C:\sesame\data\email.doc")
      Clear(Mark)
      }
 



Please don't worry about my using a layout element instead of a variable. I used the element on purpose to see what was in the "Mark" LE at any point in time. WHEN (not "IF" but "WHEN") I get it working, I will use a variable instead of the layout element. As I said, this works just fine but with a long delay.

If I OMIT the @loiter command, then what gets inserted is the PREVIOUSLY saved document; it does not reflect the most recent one saved.

In this situation (with @loiter ommited) then if I execute the command button a SECOND time it does enter the correct document but only after shelling out to MS Word first.

If I could get this close, it just seems to me that there MUST be a way to make it work.

Once again, here is my objective and I want this to work with one click on a Sesame command button:

 1) Click on a command button in Sesame  
 2) Have MS Word automatically open and present me with email.doc
 3) Modify and save my email doc.
 3) Exit Word which will return me to Sesame
 4) Have Sesame insert the e-mail doc

PLEASE tell me I'm on the right track and what it is that I am overlooking.  I must get on with my "other" (@isblank(Sesame) life.  lol

« Last Edit: Feb 5th, 2006 at 6:34am by SpencerWulwick »  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Open MS Word with Sesame value?
Reply #7 - Feb 4th, 2006 at 9:38pm
Print Post Print Post  
There are a few of sticking points here. I'm on Linux at the moment so I can't test the specifics, but from what I believe:

1. Using ASynchShell will cause things to run asynchronously (as the name implies). If you want to wait for something to complete, you probably want to use @Shell instead, which is synchronous (waits for the command to complete before returning).

2. MSWord probably runs asynchronously no matter how you invoke it.

3. MSWord isn't very useful for producing ASCII, and ASCII is the only format that can be accurately imported using @Insert.

Why not use a text editor (instead of MSWord) that produces ASCII files as the native format, and run it synchcronously? There are hundreds of text editors to choose from, including two that come with MSWindows ("edit" and "notepad").

If you try to load a binary file (native MSWord format is binary) using @insert, it is likely that you will only be able to insert a portion of the file and that the portion you can insert will be unusable inside Sesame. If you, later, save that data to a new file, it is likely to be unusable in MSWord or any other program.

If you absolutely must use MSWord, make sure you save the file in one of the supported ASCII formats. The ASCII ".txt" format is okay. If you need to retain the fonts, text formatted, etc... you can use the "rich text format" (".rtf") which is also ASCII.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Open MS Word with Sesame value?
Reply #8 - Feb 4th, 2006 at 9:46pm
Print Post Print Post  
Mark -

I have to run out so I can't try anything now; however, I am very anxious to get this completed.

I prefer to use MS Word and have no problem saving it as a plain text (.txt) file nor do I have any problem importing the text file into Sesame so it does not appear that using MS Word has anything to do with the situation I am trying to rectify.

My problem is that I want the insert to execute after my return to Sesame without further user input.

As I said I have it working but only with the loiter command and only if I return to Sesame before loiter is completed.

I had tried @shell but had less success with that. 

So, I am still hoping to get some help on this from one of the programming gurus.

Once again, I want to click on a command button, have Sesame execute a shell (of some kind) command and when I return to Sesame after exiting the other program, have the remainder of the programming executed.

Thanks!
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Open MS Word with Sesame value?
Reply #9 - Feb 4th, 2006 at 9:48pm
Print Post Print Post  
Hi Spencer, thanks for joining us at SANE Users Group today.  With our new internet connection 2 hrs before we left, it was nice to have the Skype connection working with you.  Next time we will have a mike.

-------------------------------------------------------
Here is a thought re your problem here.......

Have you tried adding more code to follow the shell to Word?
You could also create a macro in Word to save a filename.txt when done.  The programming following Shell could loop until filename.txt exists, and then continue on, knowing that Word had been completed.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Open MS Word with Sesame value?
Reply #10 - Feb 5th, 2006 at 6:28am
Print Post Print Post  
Bob -

What a treat it was to hear from you at your user's group today.  Very frustrating, though, that I couldn't hear you, although you were able to hear me.  I do hope you'll have a mike and perhaps a video cam at the next meeting.  Having been to your meetings in the past, I "ached" to hear about the meeting and not to have been there.

As for your suggestion, I don't know what you mean by "additional coding." Anything that would work would be welcomed but, at this point, after all it took for me to get this far, I guess I need some specific coding.

As for a macro in Word, I don't think that is needed.  I envsioned initially establishing a doc called filename.txt that Sesame would open when starting Word.  Simply saving and exiting Word is all that is needed.

Likewise, because the filename.txt document would "always" exist, "looping until it exists" would not work.

As I said, I am so close that I can't believe it is not doable.  I believe we already have all the necessary tools and commands and that it is just a matter of putting it together correctly.

I've made incredible progress since I first started toying with this but just can't seem to visualize the last missing piece.  

Ray, wherefore art thou?  lol
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Open MS Word with Sesame value?
Reply #11 - Feb 5th, 2006 at 2:38pm
Print Post Print Post  
Quote:
Mark -

I have to run out so I can't try anything now; however, I am very anxious to get this completed.

I prefer to use MS Word and have no problem saving it as a plain text (.txt) file nor do I have any problem importing the text file into Sesame so it does not appear that using MS Word has anything to do with the situation I am trying to rectify.

As long as you do remember to use MSWord in ASCII only mode. But, MSWord is still asynchronous, so it may return to @Shell immediately - before the user is done using it.
Quote:
My problem is that I want the insert to execute after my return to Sesame without further user input.

As I said I have it working but only with the loiter command and only if I return to Sesame before loiter is completed.

I had tried @shell but had less success with that.

Does it return immediately if you invoke it using the full path and executable name instead of using the file association when using @Shell? 
Quote:
So, I am still hoping to get some help on this from one of the programming gurus.

Once again, I want to click on a command button, have Sesame execute a shell (of some kind) command and when I return to Sesame after exiting the other program, have the remainder of the programming executed.

Thanks!


If you use MSWord and save the primary file as ASCII text, and run MSWord asynchronously (either because you used @ASynchShell, or because MSWord insists on being asynchronous), you could use a second file, deleting it before MSWord is launched, then writing it with a macro in MSWord when done, and in a while loop in SBasic, checking if the second file exists. Or you could read the primary file to see if it has changed, again using a timer in a while loop.

It would probably be easier to find a way to run MSWord (or another text editor) synchronously.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Open MS Word with Sesame value?
Reply #12 - Feb 5th, 2006 at 3:28pm
Print Post Print Post  
Spencer,

If your file is indeed saved as plain text, this might be much easier to approach from the other direction.

Say you want to insert the value in an element called FirstName into your doc.

1. Type your doc in Word (or any text editor). In the space where you want FirstName to appear, type a tag like [FirstName]. Save the doc as plain text.

2. In Sesame, program your button with something like the following:

Code
Select All
var vDoc as String

    vDoc = @Insert("email.txt")
    vDoc = @Replace(vDoc, "[FirstName]", FirstName)
    LastEmail = vDoc
 


  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged