dialog box

L

LEU

I have the following macro that when I’m run it I want to save the formfileds
as plan text. The problem is when I open the word document from the mainframe
application the SaveAs dialog box defaults the file type to “Doc†and I want
it to default to “txtâ€. How can I do this?

Dim tempfile
Dim oFF As FormFields
Set oFF = ActiveDocument.FormFields
With Dialogs(wdDialogFileSaveAs)
Options.DefaultFilePath(wdDocumentsPath) = "U:\History"
.Name = ""
If .Display = -1 Then
tempfile = .Name
Open tempfile For Output As #1
Write #1, oFF(5).Result, oFF(6).Result, oFF(7).Result, _
oFF(8).Result, oFF(9).Result, oFF(10).Result
Close #1
End If
End With
Set oFF = Nothing
 
L

Lene Fredborg

Try to insert this code line:
..Format = wdFormatText
immediately above or below the line
..Name = ""

It works under “normal†Word conditions but I don’t know whether it will
work in your situation.

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
P

Perry

Here's an alternative for Office versions XP up ...

Dim fd As FileDialog

Set fd = Application.FileDialog(3)
fd.Filters.Add "Text Files", "*.txt"
fd.FilterIndex = 0
fd.InitialFileName = "U:\History"
fd.AllowMultiSelect = False
If fd.Show Then
MsgBox fd.SelectedItems(1)
End If

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 
L

LEU

Hi Perry,

We are using Office XP. How do I write and save my "oFF( ).results" to the
text file? With your code it opens a Look In dialog box not a Save As dialog
box.

LEU
 
P

Perry

We are using Office XP. How do I write and save my "oFF( ).results" to the
text file? With your code it opens a Look In dialog box not a Save As
dialog
box.

?
the FileDialog isn't used to save your textfile.
It is merely used to retrieve the textfile the user needs to select, to
write the results of the formfields to.
At least, this is what understood from yr initial post.
(If this assumption is not correct, than correct me :)

I've combined my proposal to yr initial post, see below code.
Try the code, and pls check whether formfields data is actually written to
(and saved in) the textfile?

' Here is the code
Dim tempFile
Dim fd As FileDialog
Dim oFF as formfields
Dim i as integer
set oFF = activedocument.formfields

i = FreeFile()

Set fd = Application.FileDialog(3)
fd.Filters.Add "Text Files", "*.txt"
fd.FilterIndex = 0
fd.InitialFileName = "U:\History"
fd.AllowMultiSelect = False
If fd.Show Then
tempFile = fd.SelectedItems(i)
Open tempfile For Output As #i
Write #i, oFF(5).Result, oFF(6).Result, _
oFF(7).Result, oFF(8).Result, _
oFF(9).Result, oFF(10).Result
Close #i
End If

The code in words: FileDialog retrieves the name of the target textfile
selected by user.
The name of this textfile is used in the Open ... For Output command to open
an I/O channel to target textfile, using #i (retrieved by FreeFile function)
The results of the FormFields (5, 6, 7, 8, 9 and 10) are written to the
target textfile.
Data is written to textfile, so the I/O channel can be closed. If no errors
occur, all data is saved to this textfile ...

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 
L

LEU

Thank you so much. This worked perfectly.

LEU


Perry said:
?
the FileDialog isn't used to save your textfile.
It is merely used to retrieve the textfile the user needs to select, to
write the results of the formfields to.
At least, this is what understood from yr initial post.
(If this assumption is not correct, than correct me :)

I've combined my proposal to yr initial post, see below code.
Try the code, and pls check whether formfields data is actually written to
(and saved in) the textfile?

' Here is the code
Dim tempFile
Dim fd As FileDialog
Dim oFF as formfields
Dim i as integer
set oFF = activedocument.formfields

i = FreeFile()

Set fd = Application.FileDialog(3)
fd.Filters.Add "Text Files", "*.txt"
fd.FilterIndex = 0
fd.InitialFileName = "U:\History"
fd.AllowMultiSelect = False
If fd.Show Then
tempFile = fd.SelectedItems(i)
Open tempfile For Output As #i
Write #i, oFF(5).Result, oFF(6).Result, _
oFF(7).Result, oFF(8).Result, _
oFF(9).Result, oFF(10).Result
Close #i
End If

The code in words: FileDialog retrieves the name of the target textfile
selected by user.
The name of this textfile is used in the Open ... For Output command to open
an I/O channel to target textfile, using #i (retrieved by FreeFile function)
The results of the FormFields (5, 6, 7, 8, 9 and 10) are written to the
target textfile.
Data is written to textfile, so the I/O channel can be closed. If no errors
occur, all data is saved to this textfile ...

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 
L

LEU

Perry,

I spoke to soon. Your code works great copying the text doc into my document
by changing the following line, “Open tempfile For Input As #iâ€, but the wat
it is writen it does not write from my document into a text document. When it
runs it calls up the browse dialog box. If I enter a new name to save it as
and click OK, nothing happens. Shouldn't it be opening the Save As dialog box?

LEU
 

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