View Full Version : Solved: Filedialog property
samuelwright
12-08-2005, 04:16 AM
My friend says that he cannot get the FileDialog Property in Word 2000.
i.e.
Dim Something as FileDialog
I have only got Word 2003, and have no access to Word 2000. Is he telling the truth?
Marcster
12-08-2005, 04:30 AM
Hi Samuel,
He's correct. In Word there's no FileDialog
In Word 2000 you can use:
With Dialogs(wdDialogFileOpen)
..some code here
Marcster.
samuelwright
12-08-2005, 04:36 AM
Hi Marcster
I have the following code (written for Word 2003, and it works). how do I modify it using your suggestion?
Private Sub okButton_click()
Dim dlgSaveAs As FileDialog ' the offending line in Word 2000!!!
Dim Path As String
Path = ActiveDocument.Path
If Path = "" Then
Path = Options.DefaultFilePath(wdDocumentsPath)
End If
Path = Path + "\"
If ValidFileName Then ' i.e. the file path name contains no illegal characters
'Save file with new extension
Set dlgSaveAs = Application.FileDialog(FileDialogType:=msoFileDialogSaveAs)
dlgSaveAs.InitialFileName = Path + Trim(FileName) + ".doc"
dlgSaveAs.Show
dlgSaveAs.Execute
Unload SubjectNameForm
Else
MsgBox ("Invalid Filename - the characters / \ : * "" < > | $ & ' ` ? are not _
allowed in a Filename"), vbCritical
End If
End Sub
Marcster
12-08-2005, 06:14 AM
In Word 2000 you display the SaveAsDialog like this:
With Dialogs(wdDialogFileSaveAs)
.Name = Path
.Show
End With
But I can't see a way to get the (Path + Trim(FileName) + ".doc") in the filename box.
There's this, which saves the Doc:
ActiveDocument.SaveAs FileName:=Path + Trim(FileName) + ".doc"
But that doesn't show the SaveAs Dialog.
Do you need to display the SaveAs Dialog?.
Marcster.
samuelwright
12-08-2005, 06:35 AM
Hi Marcster
Basically, here is what I want this to do in 2000 as well as 2003:
A Userform is loaded when the user clicks a button. This form produces a string in a text box called FileName. When the user does okbutton_click() on the userform, I want to transfer that string to the Save As dialog box in the Save As window.
Does that explain things or have I got the wrong idea?
sam
samuelwright
12-08-2005, 06:48 AM
Hey Marcster,
Never mind just been playing around, think I get you now!!! This seems to work for 2003, does it work for 2000?
Private Sub okButton_click()
Dim Path As String
Path = ActiveDocument.Path
If Path = "" Then
Path = Options.DefaultFilePath(wdDocumentsPath)
End If
Path = Path + "\"
If ValidFileName Then 'i.e. the file path name contains no illegal characters
With Dialogs(wdDialogFileSaveAs)
.Name = Path & Trim(FileName) & ".doc"
.Show
End With
Else
MsgBox ("Invalid Filename - the characters / \ : * "" < > | $ & ' ` ? are not allowed in a Filename"), vbCritical
End If
End Sub
Much obliged
Marcster
12-08-2005, 07:01 AM
I'll just check... :type
Marcster.
Marcster
12-08-2005, 07:20 AM
I've ran the code...
FileName, used on this line :
.Name = Path & Trim(FileName) & ".doc"
is not defined in your code.
Fix:
Dim FileName As String
FileName = 'Name of file here'
Once the above has been inserted, yep, :)
shows the SaveAs dialog.
In the dialog the File name box displays
the contents of FileName. :)
Marcster.
samuelwright
12-08-2005, 07:40 AM
Ah, sorry, should have mentioned, FileName is a string output from the userform that this procedure is embedded in... Cheers Marcster!!
Marcster
12-08-2005, 07:45 AM
Thats OK then.
Glad I could help. :yes
Marcster.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.