I'm using a button "btnProcess" to save an excel file using MSOFileDialogSaveAS vba to open a file path for users to save to a folder in the open path or from there navigate to a desired path of the user. Below is what I have designed to open the path to \Acctstmt.
Every time I press btnProcess I get the error message "Compile error: Variable not Defined" highlighting "Set FDir = Application.FileDialog (msoFileDialogSaveAs)" in the vba code editor.
Please can you kindly review the below and please advise of what I am doing wrong or give me some suggestions related to MSOFileDialogSaveAs.
Dim MyExpFilename As String
Dim MyExpPath As String
Dim FDir As Object ' Used Object type instead of STRING for late binding
Dim strQ As String
Dim strF As String
Dim TempF As String
Dim OpenF_Path As String
Dim ExportF_Excel As String
Dim AppEx As Object ' Used Object type instead of STRING for late binding'
Dim myWork As Object ' Used Object type instead of STRING for late binding
TempF = "C:\RedGrows\ScheduledAcct\AcctStmt"
strQ = Chr$(34)
ExportF_Excel = "\8 Excel-" & Me.GetStore & Me.Ref
MyExpFilename = TempF & ExportF_Excel
OpenF_Path = strQ & TempF & "" & ExportF_Excel & ".xlsx" & strQ
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "qry_myCSVWork_Union", MyExpFilename, True
Set AppEx = CreateObject("Excel.Application")
Set myWork = AppEx.Workbooks.Open(OpenF_Path)
AppEx.Visible = True
With myWork
' Display Save As dialog to choose new location
Set FDir = Application.FileDialog(msoFileDialogSaveAs) 'Compile Error message highlights this line in the code editor
With FDir
.InitialFileName = MyExpFilename
If .Show = -1 Then
MyExpPath = .SelectedItems(1)
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "qry_myCSVWork_Unin", MyExpPath, True
End If
End With
myWork.Close True
End With
Set AppEx = Nothing
Set myWork = Nothing
Kill (TempF & "" & ExportF_Excel & ".xlsx")