Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

From Outlook to .dot ...

Status
Not open for further replies.

PerlIsGood

Programmer
Jan 24, 2002
154
US
... or .doc using form fields within the Word file.

I'm working on a custom form in Outlook and am wondering how I would go about sending information to a .dot or .doc file using the values generated in the form. I'm sorry to be posting a question without some sort of attempted code to present, but in this instance I'm not even sure where to begin.

Any help would be appreciated.
 
im a total newbie but maybe someting like this would help you get started found it in a vbscript book by wrox press

Dim objFSO
set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
If IsObject(objFSO) Then
Set oShell = WScript.CreateObject("WScript.Shell")
oShell.Run "notepad"
oShell.AppActivate("notepad")
oShell.SendKeys "hello, world"
set objFSO = Nothing
End If
 
PerlIsGood:

I'm confused - do you want to create/update a Word document on the server side, or on the client?

In any case, you should consider working with the RTF format instead (RichText), since rtf files do not contain macros, and therefore cannot easily be made to carry computer viruses. RTF files do contain some text formatting information, and can be opened (and created) using most word processors, including Word, making them a good format for sharing files with other users.

RTF file output can be produced "on the fly" by any script language. More information about this standard can be found at Microsoft's Support Site - download the latest specification from
I mention this, since I never handle Word documents over the web anymore (not even from "known" sources, unless I can check them for viruses first) after having seen the havoc that macro viruses can wreak!

DrMaggie
---------
"Those who don't know the mistakes of the past won't be able to enjoy it when they make them again in the future."
— Leonard McCoy, MD (in Diane Duane's Doctor's Orders)
 
First, thanks for the RTF link.

To clarify, I have a custom form in Outlook that will be used by a specific (and small) group of users over a LAN. What I'm attempting to ascertain is whether it is possible to take values in this form and transfer them to a MSWord (or create an RTF) document that contains 'form fields' and then filling these form fields with the desired information from the Outlook form.

For example; I have a variable named txtGreeter representing a text field in the Outlook form. In a corresponding Word.doc there is a 'form field' labeled txtGreeter (or whatever): Is there a way to place the outlook values into the document?

Since this is only being used internally, do you still believe RTF would be a more usable format? If so, and due to the fact that I'm a complete newbie in the VB(and family) arena, how would you instantiate the RTF object and then begin populating it?

(If that question entail a lengthy answer I apologize. I've been searching the net for anything I can find on VBScript within the Outlook environment and I've found nothing to help me along -- short of books that would help those that already understand VB and family) :)
 
PerlIsGood:

Ah, I'm starting to understand what you want to do...
Let me see if I made it :)

You want to have someone enter data via a form (that you want to write for Outlook) that should be inserted into another document that also has "form capability" - I guess since you want to be able to edit that data easily later.

For this, it seems to me that Word format might be a bit too complex to "recreate" using some script - but I fear that RTF doesn't have form handling capabilities. I did a quick check, and created a short form with Word and saved it in RTF - the resultant file is a mess :)

But - mess or not - it is at least in ascii, so I took my favorite text editor and looked at it. Lo and behold, the form definition seemed to be saved amid a jumble of other stuff, which isn't needed to make the RTF file work... (But results from all the Word header and style info being saved alongside with the document content.)

Now, since I don't know exactly what platform or software you have access to or want to use, but I would attack this "problem" using a different approach, namely using a database (Access would do fine) with a webpage-form interface allowing whoever should have access to view and edit the data.

This would mean installing some web server capable of ASP (active server pages) script processing - which if you don't already have it on your system does add complexity and presents a potential security risk, unless maintained properly.

If you would like some samples of how to implement such a web form solution, let me know. (Drop me a line at drmaggie at t-online.de)

Another way, which I never tried personally but know of people who did, is to work with PDF files - which are indeed used by many institutions for creating forms and storing the entered information. PDF files also cannot contain viruses (AFAIK), which make them safe - but the drawback here [if I understand correctly] is that to be able to store the input'ed data, it has to be filled out using a "full" copy of Acrobat - i.e. the free Reader software cannot store the data :(

Perhaps you get something useful out of this rather rambling post... Anyway, good luck!

DrMaggie
---------
"Those who don't know the mistakes of the past won't be able to enjoy it when they make them again in the future."
— Leonard McCoy, MD (in Diane Duane's Doctor's Orders)
 
OK, I did some more tinkering with this idea... What I have here just might work, I'm just screwing up the syntax (I think):

1st, start with the Function in Outlook:
Code:
Function Cmd8_Click()
    Set strDriveLetter = ..., etc.

' I'm screwing something up in this area.
' Getting 'Object doesn't support method at
' oFile.CreateItemFromTemplate.

    FileLoc = strDriveLetter & FormPath & "formschedule.doc"
    Set oFile = Application.CreateObject("Word.Document")
    Set oOpen = oFile.GetFile(FileLoc)
    Set oWord = oOpen.CreateItemFromTemplate(FileLoc)
        strPop = "Populate(var1, var2, var3, etc...)"

' Here I'm trying to pass the forms variables to the
' Populate macro in Word.  Don't know if you can pass vars
' to a macro like that, if at all.

        oWord.Run strPop
        oWord.Display
    Set oWord = Nothing
End Function

2nd, write the Populate macro in Word:
Code:
Sub Populate(include vars to be passed...?)
   If FormField.Name = "var1" Then
        FormField.Value = var1
   End If

' And so on for each FormField value/variable...
End Sub

If someone could let me know whether or not I'm completely mad, that would be wonderful!
 
Ok, did yet more tinkering with this and now have most of it working to my liking:
Code:
    FormFiles = ":\path\to\file\"
    FileLoc = strDriveLetter & FormFiles & "formschedule.doc"
    Set oWord = CreateObject("Word.Application")
        oWord.Documents.Open (FileLoc)
            oWord.ActiveDocument.Bookmarks("var1").Select
            oWord.Selection.InsertBefore (var1)
    Set oWord = Nothing
I only have two problems with this:
1. I would like to know if there's a way to get this to open/use the existing word app that's already running (if one is running) instead of generating a new word app/window. This problem seems to be interfering with one of our global templates and I can't figure out how to get around it.

2. Has anyone ever worked with Word form fields before? I can only seem to insert text before/after the bookmark. Does anyone know of a way to replace/insert text inside the form field?
 
Hi,
I'm having real trouble trying to export information from a custom outlook form (from my user defined fields) to a text file or excel file.
I've created the form which is a questionnaire that will be sent to users. I would like to collect the users feed back and export it to a text file or any other file format. Is there any way to do this...?
Any help/suggestions wil be very much appreciated!!
Thanks
 
I also need help trying to export information from a custom outlook form to a text document or excel or word. Can anyone help??
 
I was eventually able to make it work. For your problem, you'd probably do something similar to what I've done below:
Code:
Set fso = CreateObject("Scripting.FileSystemObject")
FileLoc = "\Path\To\File.*"

' Checks to see if Word is already open, if not
' then open application.       
    If fso.FileExists(FileLoc) Then
        On Error Resume Next
        Set oWord = GetObject(, "Word.Application")
        If Err.Number <> 0 Then
            Err.Clear
            Set oWord = CreateObject(&quot;Word.Application&quot;)
        End If
    Else
        MsgBox (strErr), vbCritical, &quot;Error: File Not Found&quot;
        Set fso = Nothing
    End If

' Start exporting data to document.

oWord.Documents.Open (FileLoc)
oWord.ActiveDocument.FormFields(&quot;var1&quot;).Result = var1
oWord.ActiveDocument.FormFields(&quot;var2&quot;).Result = var2

An excel file or access database would probably be your best option for what you want to do. Unfortunately I have not worked with excel or access and can't give you any context-specific help. Just search through this board as well as the VBA board; I was able to answer many of my questions that way.

Well, hope this provided some help :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top