Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Allow user to modify a Word document?
Message
From
12/01/2009 10:53:26
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01372571
Message ID:
01372805
Views:
44
>> It does 1 and 2.
>OK, I give up. I spent most of the day with this yesterday and have thus far been unable to do anything more than pop up messages. References to oWord seem to be completely ignored. How, exactly, would one return control to VFP from, say, the BeforeSave event? I'm obviously doing something wrong...
>
>>You simply compile it uisng the olb you have on your machine
>But what about the instantiation? I would expect an error when this file is not present. I can't test that yet of course....

I don't understand, that file is there during compilation, no? If you mean you don't have access to Office on your development machine then maybe instead you would want to create a word automation project in .Net. I am not sure but probably VSTO is publicly available.


All you need is to change the olb if this is not the one on your machine (I have W2003 on this machine and w2007 at home).
lcGetFile = Getfile('DOC')

Local oword As 'word.application'
oword = Newobject('word.application')
oWordEvents = Newobject("WordEvents",'','',oword)
Eventhandler(oword,oWordEvents)
With oword
  .Documents.Open(m.lcGetFile)
  .Visible = .T.
  .Activate
Endwith


Define Class WordEvents As Session OlePublic
  Implements ApplicationEvents2 In "C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE11\MSWORD.OLB"

  oHook = Null
  Procedure Init(loHook)
    This.oHook  = loHook
  Endproc

  Procedure ApplicationEvents2_Quit() As VOID
    ? 'User is quitting word',Datetime()
    Eventhandler(This.oHook,This,.T.)
  Endproc

  Procedure ApplicationEvents2_DocumentChange() As VOID
  Endproc

  Procedure ApplicationEvents2_DocumentOpen(Doc As VARIANT) As VOID
  Endproc
  Procedure ApplicationEvents2_DocumentBeforeClose(Doc As VARIANT, Cancel As LOGICAL) As VOID
  Endproc
  Procedure ApplicationEvents2_DocumentBeforePrint(Doc As VARIANT, Cancel As LOGICAL) As VOID
  Endproc
  Procedure ApplicationEvents2_DocumentBeforeSave(Doc As VARIANT, SaveAsUI As LOGICAL, Cancel As LOGICAL) As VOID
    Local lcUserDocName
    lcUserDocName = Doc.FullName
    Cancel = .T.
    ? 'Attempted save..Cancelled save...',Datetime()

    Local loBalloon,lVisible
    loBalloon = Doc.Application.Assistant.NewBalloon
    lVisible  = Doc.Application.Assistant.Visible
    Doc.Application.Assistant.Visible = .T.
    With loBalloon
      .Heading = "Sorry. VFP doesn't let you to save '" + m.lcUserDocName + "'" + ;
        CHR(13)+Chr(10) +;
        CHR(13)+Chr(10) +;
        "After you respond to this dialog I will return control to VFP dismissing any changes."
      .Show()
    Endwith
    Doc.Application.Assistant.Visible = m.lVisible

    #Define wdDoNotSaveChanges	0
    Doc.Application.Quit(wdDoNotSaveChanges)

  Endproc
  Procedure ApplicationEvents2_NewDocument(Doc As VARIANT) As VOID
  Endproc
  Procedure ApplicationEvents2_WindowActivate(Doc As VARIANT, Wn As VARIANT) As VOID
  Endproc
  Procedure ApplicationEvents2_WindowDeactivate(Doc As VARIANT, Wn As VARIANT) As VOID
  Endproc
  Procedure ApplicationEvents2_WindowSelectionChange(Sel As VARIANT) As VOID
  Endproc
  Procedure ApplicationEvents2_WindowBeforeRightClick(Sel As VARIANT, Cancel As LOGICAL) As VOID
  Endproc
  Procedure ApplicationEvents2_WindowBeforeDoubleClick(Sel As VARIANT, Cancel As LOGICAL) As VOID
  Endproc
Enddefine
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform