Hello,
I am trying to open an Excel Workbook from a FileDialog where the user can select the file, make changes (in this case formatting), then SaveAs a different name in the same path as the original file from a command button on an Access form. Everything works except saving the file as a different name.
I am trying to open an Excel Workbook from a FileDialog where the user can select the file, make changes (in this case formatting), then SaveAs a different name in the same path as the original file from a command button on an Access form. Everything works except saving the file as a different name.
Dim fd As Object, sFileName As String
Set fd = Application.FileDialog(3)
With fd
.AllowMultiSelect = False
.Title = "Browse to Select a File"
If .Show = -1 Then sFileName = .SelectedItems(1)
End With
'Change the column headings on the spreadsheet
If Len(sFileName) = 0 Then Exit Sub
Dim xlObj As Object
Set xlObj = CreateObject("Excel.Application")
With xlObj
.Workbooks.Open sFileName
.Visible = True
.Worksheets.Select
.Cells.Select
.Selection.Replace What:="=", Replacement:="'="
.ActiveWorkbook.SaveAs FileName:="NewFile" & sFileName
.Quit
End With
Set fd = Nothing
Set xlObj = Nothing
Last edited: