Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Word - Prompt for file name 1

Status
Not open for further replies.

bxgti4x4

Technical User
Feb 22, 2002
167
GB
I have a Access Report which is exported as a Word document and is subsequently imported into a new Word document. The import action is part of a macro in Word in which I wish to include a VBA statement for saving the final Word document under a new name.

I can find the code
Code:
Active Document.SaveAs File Name
but this requires me specify the new file name in the code whereas I need the code to prompt me for the file name.

Can anyone please advise me how I can do this

John
 
Why don't you create an inputbox to get the value you want and then add that to the code as below (not tested)
Code:
fil$ = Inputbox("Please enter File Name")
If right(fil$,4) <> ".doc" then
  fil$ = fil$ & ".doc"
End if
Active Document.SaveAs fil$
 
I think this is what you are after:

Code:
Application.Dialogs(wdDialogFileSaveAs).Display

Let me know if that does it for you.

VBAjedi [swords]
 
Thanks VBAjedi that was just what I was looking for.

Many thanks,
John
[2thumbsup]


 
I'm trying to do the same thing in Access, but the property .Dialogs is not coming up for Application. Do I need to install an additional component from my MS Office CD?
 
Application.Dialogs is a collection in Word object model.
For access, depending of your version, you may consider Application.FileDialog

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Another way, that works in Excel but I'm not too sure if it will work in Access is:

file_name = Application.GetSaveAsFilename
 
I'm thinking I must be missing a reference because I am getting no love on any of the above.

The class references I have installed are:
VB for applications
Microsoft Access 9.0 Object Library
OLE Automation
Microsoft ActiveX Data Objects 2.1 Library
Microsoft DAO 3.51 Object Library

The front end is programmed using VB 6.0, but this one goofy form that I need to select a file in is in Access itself because I don't want the end users to have access to the import function - just DB Managers (me).
 
Add the Microsoft Office reference to see if you have access to the FileDialog object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Access 9.0 is Access 2000 so I don't think you will have FileDialog available - it came in with XP.

I think you will need to use APIs something like:
Code:
[blue]Declare Function GetSaveFileName _
        Lib "comdlg32.dll" _
        Alias "GetSaveFileNameA" _
            (pSaveFileName As SAVEFILENAME) _
        As Boolean

Private Type SAVEFILENAME
    lStructSize         As Long
    hwndOwner           As Long
    hInstance           As Long
    lpstrFilter         As String
    lpstrCustomFilter   As String
    nMaxCustFilter      As Long
    nFilterIndex        As Long
    lpstrFile           As String
    nMaxFile            As Long
    lpstrFileTitle      As String
    nMaxFileTitle       As Long
    lpstrInitialDir     As String
    lpstrTitle          As String
    flags               As Long
    nFileOffset         As Integer
    nFileExtension      As Integer
    lpstrDefExt         As String
    lCustData           As Long
    lpfnHook            As Long
    lpTemplateName      As String
End Type

Private Function GetSaveAsName() As String
    
    Dim SaveAsFile As SAVEFILENAME
    
    With SaveAsFile
    
        .lStructSize = Len(SaveAsFile)
        
        .hwndOwner = 0
        .hInstance = 0
        .lpstrFile = Space$(254)
        .nMaxFile = 255
        .lpstrFileTitle = Space$(254)
        .nMaxFileTitle = 255
        .lpstrInitialDir = Chr$(0)
        .flags = 0
        .lpstrTitle = "Enter FileName to Save As"
        .lpstrFilter = "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
    
    End With
    
    If GetSaveFileName(SaveAsFile) Then _
        GetSaveAsName = Trim$(SaveAsFile.lpstrFile)

End Function

Sub Test()
    MsgBox GetSaveAsName
End Sub[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top