Consulting

Results 1 to 10 of 10

Thread: Solved: Filedialog property

  1. #1

    Solved: Filedialog property

    My friend says that he cannot get the FileDialog Property in Word 2000.

    i.e.

    [VBA]
    Dim Something as FileDialog
    [/VBA]


    I have only got Word 2003, and have no access to Word 2000. Is he telling the truth?

  2. #2
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Hi Samuel,
    He's correct. In Word there's no FileDialog
    In Word 2000 you can use:
    [VBA] With Dialogs(wdDialogFileOpen)
    ..some code here
    [/VBA]

    Marcster.

  3. #3
    Hi Marcster

    I have the following code (written for Word 2003, and it works). how do I modify it using your suggestion?

    [VBA]
    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

    [/VBA]

  4. #4
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    In Word 2000 you display the SaveAsDialog like this:
    [VBA]
    With Dialogs(wdDialogFileSaveAs)
    .Name = Path
    .Show
    End With
    [/VBA]
    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:
    [VBA]
    ActiveDocument.SaveAs FileName:=Path + Trim(FileName) + ".doc"
    [/VBA]
    But that doesn't show the SaveAs Dialog.

    Do you need to display the SaveAs Dialog?.

    Marcster.

  5. #5
    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

  6. #6
    Hey Marcster,

    Never mind just been playing around, think I get you now!!! This seems to work for 2003, does it work for 2000?

    [VBA]
    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[/VBA]

    Much obliged

  7. #7
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    I'll just check...

    Marcster.

  8. #8
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    I've ran the code...

    FileName, used on this line :
    [VBA]
    .Name = Path & Trim(FileName) & ".doc"
    [/VBA]
    is not defined in your code.
    Fix:
    [VBA]
    Dim FileName As String
    FileName = 'Name of file here'
    [/VBA]
    Once the above has been inserted, yep,
    shows the SaveAs dialog.
    In the dialog the File name box displays
    the contents of FileName.


    Marcster.

  9. #9
    Ah, sorry, should have mentioned, FileName is a string output from the userform that this procedure is embedded in... Cheers Marcster!!

  10. #10
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Thats OK then.

    Glad I could help.

    Marcster.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •