Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2007

Tip: Looking for answers? Try searching our database.

dialog box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LEU - 10 Mar 2007 23:31 GMT
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
Lene Fredborg - 11 Mar 2007 12:09 GMT
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.

Signature

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

> 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
[quoted text clipped - 16 lines]
> End With
> Set oFF = Nothing
Perry - 11 Mar 2007 14:31 GMT
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

>I have the following macro that when I’m run it I want to save the
>formfileds
[quoted text clipped - 19 lines]
> End With
> Set oFF = Nothing
LEU - 11 Mar 2007 23:39 GMT
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

> Here's an alternative for Office versions XP up ...
>
[quoted text clipped - 40 lines]
> > End With
> > Set oFF = Nothing
Perry - 12 Mar 2007 00:48 GMT
> 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

> Hi Perry,
>
[quoted text clipped - 49 lines]
>> > End With
>> > Set oFF = Nothing
LEU - 12 Mar 2007 04:30 GMT
Thank you so much. This worked perfectly.

LEU

> > 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
[quoted text clipped - 105 lines]
> >> > End With
> >> > Set oFF = Nothing
LEU - 12 Mar 2007 19:51 GMT
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



> > 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
[quoted text clipped - 105 lines]
> >> > End With
> >> > Set oFF = Nothing
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.