• Skip to main content
  • Skip to primary sidebar

Ryan McCormick

Save File With File Dialog In VBA | Access

February 16, 2015 by Ryan 2 Comments

A couple of years ago, I posted code for selecting a file with VBA. This example demonstrates how to use the file dialog to return a Save-As string.

VBA File Dialog Save-As

'--------------------------------------------------
' File Dialog Save-As
'--------------------------------------------------
'NOTE: To use this code, you must reference
'The Microsoft Office 14.0 (or current version)
'Object Library by clicking menu Tools>References
'Check the box for:
'Microsoft Office 14.0 Object Library in Access 2010
'Microsoft Office 15.0 Object Library in Access 2013
'Click OK
'--------------------------------------------------
Public Function saveFileAs() As String
    Dim fd As FileDialog, fileName As String
    
    On Error GoTo ErrorHandler
    
    Set fd = Application.FileDialog(msoFileDialogSaveAs)
 
    If fd.Show = True Then
        If fd.SelectedItems(1) <> vbNullString Then
            fileName = fd.SelectedItems(1)
        End If
    Else
        'Stop Code Execution for Null File String
        End
    End If
 
    saveFileAs = fileName
 
    'Cleanup
    Set fd = Nothing
 
    Exit Function
 
ErrorHandler:
    Set fd = Nothing
    MsgBox "Error " & Err & ": " & Error(Err)
 
End Function

Filed Under: VBA Tagged With: access, file dialog, save as, vba

Reader Interactions

Comments

  1. Leandro Barbosa says

    March 23, 2018 at 1:47 pm

    Excelent! Thank you!

    Reply
  2. Carl Sansfaçon says

    May 17, 2018 at 12:06 pm

    Thanks !!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • Force Quit Kill all Chrome Windows MacOS
  • SOLVED: Angular 6 CLI Karma Stuck in Single Run | Karma Stops Running
  • How to Manually Install Java 8 on Ubuntu 18.04 LTS
  • Remove VirtualBox from Ubuntu 16.04 Xenial
  • Clear all Node Modules Folders Recursively Mac/Linux

Recent Comments

  1. KKV on Webstorm adding spaces between imports and braces | JavaScript and TypeScript
  2. jusopi on Clear all Node Modules Folders Recursively Mac/Linux
  3. Qaisar Irfan on Clear all Node Modules Folders Recursively Mac/Linux
  4. mustafa on Remove VirtualBox from Ubuntu 16.04 Xenial
  5. Pourya on How to Manually Install Java 8 on Ubuntu 18.04 LTS

Copyright © 2025 · Magazine Pro on Genesis Framework · WordPress · Log in