Saving FieldForm data and Non-FieldForm data in a protected documentvia macro

B

b.hammond

I'm trying to archive report data from daily MSWord reports.

The reports contain field forms and non field forms (free flow text)
in a protected document. I can save the data from the fields easily
enough by using "SaveFormsData:=True", (results in a text document
where each field is separated by a comma) I can them import the
resulting data from the fields nicely into excel, the problem is I'm
trying to also import the free flow word text from the same report and
append it to the fields data?

I was thinking something like, (data i'm trying to capture then append
is in section 2 of the .doc)

Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=2,
Name:=""
Selection.Find.ClearFormatting
Selection.WholeStory

Now how do I append the "selection.wholestory" to the .txt file
created from the forms data?

Hope I've explained my question appropriately.

Any help would be greatly appreciated.

Regards
 
D

David Horowitz

If all you want to do is append a Range of the Document to a textfile, you
could use code similar to this:
Sub WriteSelection()
Open "c:\testfile.txt" For Append As #1
Print #1, Replace(Selection, vbCr, vbCrLf)
Close #1
End Sub
That's using the old old old Open # / Close # built in VB statements. These
days, many people use the FileSystemObject to accomplish such things.
There will be issues with doing it this way - the way Word stores the text
internally is not necessarily the way you would want it written out to a
text file. Specifically, special objects and characters, like FormFields,
Section Breaks, Line Breaks, etc. have special codes inside Word and when
you write them out, it might get slightly funky.
That's why I used the Replace() call in the example - to handle the common
case of paragraph marks - Word will write out a paragraph mark as a
Chr$(13) - a vbCr. But in Windows text files, you'll want two characters for
a line break - vbCrLf - which corresponds to Chr$(13) followed by Chr$(10).
So the Replace() call replaces vbCr with vbCrLf.
Not a perfect solution, but just in case you were looking for another way to
accomplish what you're looking to do, in addition to the great MVP pages
Doug sent you.
 
B

b.hammond

See the following pages from fellow MVP Greg Maxey's website:

http://gregmaxey.mvps.org/Extract_Document_Data.htm

http://gregmaxey.mvps.org/Extract_Form_Data.htm

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com













- Show quoted text -

I've finally got this working quite nicely now, thanks for all the
help.

One more thing though, I'm having an issue with the sorting of the
file list i'm importing into Access.
Once the filearray is built, i'm not sure how to sort it, it appears
in a random order when viewing it in access. I can sort it in Access
(ascending/descending) but that messes things up when using a form to
scroll through the records. I tried sorting the directory where the
target files reside but the code that retrieves the files seems to
pick them at random. Basically I just need to sort the filearray by
date (if possible). Thanks again...
 
D

Doug Robbins - Word MVP on news.microsoft.com

You can use the following to sort the array

SortColumn1 = 0
For i = LBound(ArrayName, 1) To UBound(ArrayName, 1) - 1
For j = LBound(ArrayName, 1) To UBound(ArrayName, 1) - 1
Condition1 = ArrayName(j, SortColumn1) > ArrayName(j + 1,
SortColumn1)
If Condition1 Then
For y = LBound(ArrayName, 2) To UBound(ArrayName, 2)
t = ArrayName(j, y)
ArrayName(j, y) = ArrayName(j + 1, y)
ArrayName(j + 1, y) = t
Next y
End If
Next j
Next i


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

See the following pages from fellow MVP Greg Maxey's website:

http://gregmaxey.mvps.org/Extract_Document_Data.htm

http://gregmaxey.mvps.org/Extract_Form_Data.htm

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com













- Show quoted text -

I've finally got this working quite nicely now, thanks for all the
help.

One more thing though, I'm having an issue with the sorting of the
file list i'm importing into Access.
Once the filearray is built, i'm not sure how to sort it, it appears
in a random order when viewing it in access. I can sort it in Access
(ascending/descending) but that messes things up when using a form to
scroll through the records. I tried sorting the directory where the
target files reside but the code that retrieves the files seems to
pick them at random. Basically I just need to sort the filearray by
date (if possible). Thanks again...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top