I have a model which imports data from another Excel file and then saves it under a different name. A user can put any name as the model opens a Save As dialogue box. In case a user wants to cancel the save as operation, it should just give an option to close the model without saving. The code that does it is as follows:
The code worked fine but now my personal drive has been migrated to OneDrive (which is as usual on C:\Users\USERNAME\OneDrive and for some reason it doesn't always save the file there. The file name remains the same. Not sure what is going on. The code is a part of a larger macro.
VBA Code:
Dim FileSaveAs As Variant
Dim wb As Workbook
Dim activeWB As Workbook
Dim bFileSaveAs As Boolean
Dim templvar As Variant
'Import data
templvar = IIf(UserForm1.radioift, Array("Products", "Types"), Array("Products"))
Set activeWB = Application.ActiveWorkbook
FileOpenDial = Application.GetOpenFilename(FileFilter:="Excel Files (*.XML), *.XML", Title:="Select File To Be Opened")
'cancel pressed
If FileOpenDial = False Then Exit Sub
Set wb = Workbooks.Open(FileOpenDial, 0, True)
wb.Worksheets(templvar).Copy Before:=activeWB.Sheets(1)
wb.Close savechanges:=False 'or True
'Save a file
FileSaveAs = Application.GetSaveAsFilename(FileFilter:="Exel Files (*.xlsx), *.xlsx", Title:="Select Name To Save The File")
If FileSaveAs <> False Then
ActiveWorkbook.SaveAs Filename:=FileSaveAs, _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End If
The code worked fine but now my personal drive has been migrated to OneDrive (which is as usual on C:\Users\USERNAME\OneDrive and for some reason it doesn't always save the file there. The file name remains the same. Not sure what is going on. The code is a part of a larger macro.